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?

6
  • Ca you share the sample code? Commented Mar 7, 2018 at 19:25
  • @VivekKumarSingh did it Commented Mar 7, 2018 at 19:26
  • Could this be ran as a scheduled task possibly? That way it doesn't require a user to login and start the script. Commented Mar 7, 2018 at 20:03
  • How could I be able to do this? Commented Mar 7, 2018 at 20:09
  • 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? Commented Mar 7, 2018 at 20:10

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.