powershell - 交互式 SendKeys PowerShell 脚本
问题描述
不是选择我必须移植一个 Sendkeys 脚本才能使用 PowerShell 运行。我们使用这个每天备份的应用程序,唯一的方法是通过应用程序手动完成。因此,为了避免每天都坐在那里手动操作,我创建了一个 Sendkeys 脚本,当我手动运行它时它可以顺利运行。但是,问题在于我何时安排它。它不会打开应用程序,因此 Sendkeys 命令毫无价值。在任务计划程序中,我在程序/脚本下有“powershell.exe”,然后在添加参数(可选)下有“-ExecutionPolicy Bypass c:\users\User1\desktop\MIP_Backup_NpsSqlSys.ps1”。我还将文件夹和 exec 添加到 Windows 10 路径并验证它在那里。欢迎任何帮助。这是 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
解决方案
感谢您的帮助。
这就是我让它工作的方式。
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}")
然后我安排了它,它工作正常。
再次感谢。
推荐阅读
- python - 为 pytest 模拟 Sqlalchemy 会话
- ansible - 在ansible中将字符串设置为extra-var
- c# - 如何在基于聚合列的Linq查询中通过降序设置顺序?
- grafana - 如何监控 Grafana
- c# - 从一个公共场所转移到另一个公共场所
- react-native - 更新到 React Native 0.60.4,Jest 因不变违规而失败:__fbBatchedBridgeConfig 未设置
- javascript - ajax调用返回的jqXHR对象
- maven - 在 Spring Boot 中定义灵活的应用程序配置的更优雅的方式
- machine-learning - 反转 dropout 如何补偿 dropout 的影响并保持预期值不变?
- java - onImageAvailable 函数返回错误的图像大小