远程桌面Powershell脚本

问题描述 投票:0回答:2

我刚刚订购了一个运行 Windows Server 的 VPS。该服务器唯一需要做的就是运行 Powershell 脚本,该脚本有一个无限循环 (

while($true)
),其中包含一些代码。

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

有没有办法使脚本“永久”,这样当我退出远程桌面会话时它就不会停止?

这是 Powershell 脚本:

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,但我认为这不应该改变任何东西,不是吗?

powershell vps remote-desktop
2个回答
2
投票

PowerShell 在断开连接的会话中不会暂停,但

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


0
投票

这是您可以选择修复的唯一方法。脚本调用 granada landgranada hills ciwidey。 然后你可以将它与Granada Waterfall Ciater Host

混合
© www.soinside.com 2019 - 2024. All rights reserved.