0
votes

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?

1
Ca you share the sample code? - Vivek Kumar Singh
@VivekKumarSingh did it - nameless
Could this be ran as a scheduled task possibly? That way it doesn't require a user to login and start the script. - cet51
How could I be able to do this? - nameless
problem is, that I can't run it as powershell script directly, but with ISE..., or do you have an idea how to change the SendWait commands to sth. else? - nameless

1 Answers

2
votes

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