远程桌面Powershell脚本

时间:2018-03-07 19:23:04

标签: powershell vps remote-desktop

我刚订购了一台运行Windows Server的VPS。这个服务器唯一需要做的就是运行一个Powershell脚本,它有一个无限循环(while($true)),里面有一些代码。

一般情况下,如果我通过远程桌面连接到VPS,一切正常,它运行并运行和运行。但每当我退出远程桌面时,Powershell脚本都会暂停,并且在我再次连接之前不会继续。

有没有办法让脚本“永久”,所以当我退出远程桌面会话时它不会停止?

这是Powershell-Script:

while($true)
{
Start-Sleep 2
start chrome.exe
Start-Sleep 2
Invoke-Item C:\Users\me\index.html
Start-Sleep 2
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}") 
Start-Sleep 1000
[System.Windows.Forms.SendKeys]::SendWait("%{F4}") 
Start-Sleep 2
[System.Windows.Forms.SendKeys]::SendWait("%{F4}") 
}

顺便说一句,我从Powershell ISE启动脚本,而不是直接执行脚本,因为它不知道上下文SendKeys,但我认为不应该改变任何东西,是吗?

1 个答案:

答案 0 :(得分:1)

PowerShell不会在断开连接的会话中暂停,但SendKeys在断开连接的会话中不起作用。这是预期的行为。

相关问题