我不得不移植一个Sendkeys脚本来运行PowerShell,这不是我的选择。我们使用这个每天备份的应用程序,唯一的方法是通过该应用程序手动备份。因此,为了避免每天坐在那里手动操作,我创建了一个Sendkeys脚本,当我手动运行它时,它可以毫无故障地工作。然而,问题是我什么时候安排它。它不会打开应用程序,因此Sendkeys命令毫无价值。在任务调度器中,程序/脚本下有"powershell.exe“,然后在”Add arguments (可选)“下有"-ExecutionPolicy Bypass c:\users\User1\desktop\MIP_Backup_NpsSqlSys.ps1".”我还将文件夹和exec添加到了windows10路径中,并验证了它是否在那里。任何帮助都是受欢迎的。这是Sendkeys脚本。它打开应用程序,单击菜单并选择备份,然后选择要备份的数据库。完成后,它会给我发一封电子邮件。我确实在两者之间使用了start-sleep命令,但为了使其更简短,现在删除了它们。
'Start-Process "C:\Program Files (x86)\MIP\Progs\AcctAdv.exe"
$wshell = New-Object -ComObject wscript.shell
$wshell.AppActivate('Open Organization')
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait('admin{TAB}')
[System.Windows.Forms.SendKeys]::SendWait('PASSWORD{TAB}')
[System.Windows.Forms.SendKeys]::SendWait('DATABASE{ENTER}')
[System.Windows.Forms.SendKeys]::SendWait('%F{DOWN 2}{ENTER}')
[System.Windows.Forms.SendKeys]::SendWait('{ENTER}')
[System.Windows.Forms.SendKeys]::SendWait('{ENTER}')
[System.Windows.Forms.SendKeys]::SendWait('admin{TAB}')
[System.Windows.Forms.SendKeys]::SendWait('%{F4}')
$line1 = "MIP Backup."
$line2 = "Check the MIP backup to ensure it ran."
$line3 = "\\Server\d$\1-backups "
$line4 = "Name."
Send-MailMessage -smtpServer IP_ADDRESS_HERE -To MyEmailAddressHere.com -From MIP_Backup@One.local -Subject $line1 -Body $line2`n`n$line3`n`n$line4发布于 2021-11-16 17:13:11
谢谢你的帮助。
这就是我让它工作的方式。
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "AcctAdv.exe"
Wscript.Sleep 2000
objShell.SendKeys "USER NAME"
Wscript.Sleep 1000
objShell.SendKeys "{tab}"
Wscript.Sleep 1000
objShell.SendKeys "PASSWORD"
Wscript.Sleep 1000
objShell.SendKeys "{tab}"
Wscript.Sleep 1000
objShell.SendKeys "{tab}"
Wscript.Sleep 1000
objShell.SendKeys "{ENTER}"
Wscript.Sleep 2000
objShell.SendKeys ("%F")
Wscript.Sleep 2000
objShell.SendKeys "B"
Wscript.Sleep 3000
objShell.SendKeys ("DB NAME")
Wscript.Sleep 1000
objShell.SendKeys "{tab}"
objShell.SendKeys "{tab}"
Wscript.Sleep 1000
objShell.SendKeys "{ENTER}"
Do Until Success = True
Success = objShell.AppActivate("Finance")
Wscript.Sleep 1000
Loop
objShell.SendKeys "{ENTER}"
Wscript.Sleep 2000
objShell.SendKeys "{ENTER}"
objShell.SendKeys ("%{F4}")然后我安排了它,它工作得很好。
再次感谢。
https://stackoverflow.com/questions/69811705
复制相似问题