我试图让这个PowerShell命令脚本在批处理文件中运行,但似乎无法让它工作。先感谢您。它在PowerShell中运行良好,我只需要它就可以在bat中工作。
$wshell = New-Object -ComObject WScript.Shell;
$wshell.AppActivate('APPNAME')
Sleep 1
$wshell.SendKeys('{ENTER}');
答案 0 :(得分:0)
尽可能以最短的方式解决发生的事情,如徽标,个人资料和政策受阻:
powershell -ExecutionPolicy Bypass -NoProfile -NoLogo -Command "$wsh=New-Object -ComObject wscript.shell;$wsh.AppActivate('Appname');Start-Sleep 1000;$wsh.SendKeys('{ENTER}')"
另外,在PowerShell脚本中不需要分号,除非在同一行上分隔语句。