我正在尝试在每天的特定时间向cmd.exe窗口获取特定的重新启动命令,以便重新启动它正在运行的服务器。
我在任务计划程序中的操作目前是:
Powershell.exe -ExecutionPolicy Bypass -File C:\Rustide\restart.ps1 -verbose >> C:\Rustide\myscript.log 2>&1"
它实际上并没有创建日志,所以我认为PowerShell不会被启动。由于我需要命令在我的个人资料上运行并找到一个窗口,因此它设置为运行我的个人资料。当我自己执行脚本时,脚本运行得很好。是否有一个内置于任务调度程序的原因或安全措施不允许我这样做?如果是的话,还有一个很好的选择吗?
我已经尝试了这一点,只有当用户登录时,用户是否登录,具有最高权限等。似乎没有任何作用。
PowerShell代码
Start-Transcript -Path C:\Rustide\restart.log
Import-Module WASP
Select-Window | Where { $_.Title -Like '*OSF*Oxide' } | Set-WindowActive | Send-Keys 'restart'
start-sleep -seconds 2
通过任务计划程序执行日志。
**********************
Windows PowerShell transcript start
Start time: 20160725080935
Username: OSF-WS2012\OSF
RunAs User: OSF-WS2012\OSF
Machine: OSF-WS2012 (Microsoft Windows NT 6.3.9600.0)
Host Application: Powershell.exe -ExecutionPolicy Bypass -File C:\Rustide\restart.ps1 Start-Transcript -Path C:\Rustide\restart.log
Process ID: 10588
**********************
Transcript started, output file is C:\Rustide\restart.log
PS>$global:?
True
**********************
Windows PowerShell transcript end
End time: 20160725080937
**********************