I am trying to run a process in a VPS, but it stops working whenever I close the RDP session. The error indicates due to the screen lock the bot is not able to work.
I know I can make it work using an unattended robot but what if I want to run an attended bot, is there any possibility of keeping the VPS running without the screen getting locked even after I close the RDP season? Using any script or something. I saw a post on the forum that talks about a script, will it work on my case?
Set ws = CreateObject("WScript.Shell")
Do
Wscript.Sleep 50000
ws.SendKeys "{F15}"
Loop
This is a Windows Scripting Host (WSH) script that repeatedly sends the F15 key press to the current active application every 50 seconds, indefinitely.
Here’s a more detailed explanation:
Set ws = CreateObject(“WScript.Shell”): This line creates a new instance of the Windows Script Host Shell object which allows the script to interact with the Windows shell (the core part of the Windows operating system).
Do… Loop: This is a loop structure which will keep looping through the instructions inside it until the script is manually stopped.
Wscript.Sleep 50000: This line is making the script pause for 50,000 milliseconds (or 50 seconds) at a time.
ws.SendKeys “{F15}”: This line is making the script simulate a press of the F15 function key. The SendKeys method is a function of the WSH Shell object which allows the script to send keystrokes to the active application.
Please note that this script will run indefinitely until it is stopped or interrupted, since there is no conditional statement to break the loop.
Using a script to prevent screen lock is one way to keep the VPS running. The script you shared is useful, but it depends on the VPS environment. Certain environments may not recognize the F15 keystroke or have different settings for idle times.
Another alternative might be to check the settings provided by your VPS. Some offer settings to manage idle time or can prevent the VPS from sleeping. These settings may be in the VPS’s control panel or they could be a part of the VPS’s operating system settings.
In Windows Server environments, you can adjust the server’s Power Options to prevent the server from going to sleep.
Otherwise, you might need a more comprehensive solution, like a third-party program, to prevent the VPS from sleeping or to mimic user activity beyond simply sending keystrokes.
Every VPS provider and server setup is different so it’s hard to provide a definite answer. Please also note that changing the settings or using scripts to keep the VPS constantly active may have implications for the server’s performance and longevity. It’s always a good idea to consider the potential impact and consult with your VPS provider or an internal knowledgeable IT professional.