To Handle Ad Blocker

Prevent Desktop Lock Or Screensaver

Due to administrative rights or group policy, sometimes system gets locked or screensaver comes up after timeout. 

In this situation, most of the automation tools fails to perform the action on the application. There is a little utility (Script Program) that runs in your system tray and prevents your computer from locking or going into screensaver mode as it normally would when system is idle or no automation is running.

Even many worker of the Big company has a problem with auto logoff screensaver and they use this little utility to break rules, to make a system works all time, even he goes pi. 😄 I have found it very useful and I thought I would share it.

How to create VBScript

Microsoft VBScript (Visual Basic Script) is a general-purpose, lightweight and active scripting language developed by Microsoft that is modeled on Visual Basic. Let's create a simple program for preventing desktop lock or screensaver:

Step 1: We will create an object of WScript.Shell which is an instance of the windows shell allowing us to run commands against the windows shell from within our VBScript program. It is a powerful object that enables us to query and interact with various aspects of the Windows shell. We can display information to the user, run applications, create shortcuts, work with the Registry, and control Windows' environment variables.

 Dim objWshell : Set objWshell = CreateObject("WScript.Shell")


Step 2: We will create a Boolean type variable and assign it default value false

 vFlagStopScreensaver = False


Step 3: We will create Do Until loop having vFlagStopScreensaver - False as its condition for executing its block of code.

 Do Until vFlagStopScreensaver = False
          
 Loop     

Step 4: We will place the below two line of the code in the above loop's execution block. First line of code will make our VBScript program to wait/sleep for 60000 milliseconds (1 minutes = 60 Seconds = 60000 milliseconds). Second line of code send/press F15 Key of the keyboard which has no function assign.

 WScript.Sleep 50000
 objWshell.SendKeys "{F15}"    


Complete code will look like as appearing in the below image. Now save the program with .vbs extension anywhere or with any name (I'll prefer StopScreenSaver.vbs). To test, Double click on the file to run the program. As you will double click, it will start running in the back end.

 Dim objWshell	:	Set objWshell = CreateObject("WScript.Shell")
 vFlagStopScreensaver = False
 Do Until vFlagStopScreensaver = False
	 WScript.Sleep 50000
	 objWshell.SendKeys "{F15}"
 Loop


How to run VBScript

If you will run the program after saving anywhere on the system. It will stop running as you will restart the system. But our requirement is that it run when Robot will login the system and perform its actions/activity.

Solution of this problem is that we place this Script file on the Startup folder location so that whenever system restart then it will start running itself. Perform the below steps to do so:

  1. Open Run Command by pressing Win + R
  2. In Run Command Window, type anyone of the below line and press Enter

    %USERPROFILE%\AppData\Roaming\Microsoft\Start Menu\Programs\Startup
    OR
    shell:startup

  3. Copy and Paste the StopScreenSaver.vbs in the Startup Folder and close the folder.

It might be possible that anti-virus or any third party tool installed in your system block this script from executing. In this case, you have to mark this file safe or you have to unblock it. I hope this post is helpful. If you have any questions, feel free to comment it below.


Happy Learning.. :-)