0

I just ordered a VPS, running Windows Server. The only thing that this server needs to do is run a Powershell Script, which has an infinite loop (while($true)) with some code in it.

In general, if I connect to the VPS via Remote Desktop, everything is working fine, it runs and runs and runs. But whenever I quit Remote Desktop, the Powershell Script is paused and doesn't continue until I connect again.

Is there any way to make the script "permanent", so it doesn't halt when I quit the Remote Desktop session?

This is the 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}") 
}

By the way, I start the script from Powershell ISE, not directly execute the script, because then it doesn't know the context SendKeys somehow, but I think that shouldn't change anything, does it?

mklement0
  • 382,024
  • 64
  • 607
  • 775
nameless
  • 1,483
  • 5
  • 32
  • 78

1 Answers1

2

PowerShell does not pause in disconnected sessions, but SendKeys does not work in disconnected sessions. This is an expected behaviour.

vrdse
  • 2,899
  • 10
  • 20
  • But it seems that it gets completely paused, so its not doing anything at all (besides the keystrokes), will the script completely stop then, when `SendKeys`-Commands are in then? Could I somehow replace them, with something that continues working? or is there a way to press "Enter" in Chrome to confirm a alert dialog instead of simulating a keystroke? – nameless Mar 07 '18 at 19:40