Anti-locking VB Script using Shell Object

One of the major concerns faced while running the RPA solutions especially with UI automations(Automation Anywhere, UIpath etc) is System Locking/screen locking. In other words, while these solutions run in the background, windows gets auto locked/screen locked. Eventually this will lead to the exceptions or issues in automation solution, since the UI thread is disabled or changed. To handle such scenarios while building the automation solutions, scripts can be utilized effectivity. Below is anti-locking VB script which avoids screen from getting locked while automation executes.

Anti-Locking Script:


Sub Antilock

Dim Counter
Const Timeout=1

Set objshell=wscript.createobject("")

''on error resume next  --Enable if Required

set objWMIservice=Getobject("winmgmts:\\" & strcomputer & "\root\cimv2")

set colItems=objWMIservice.execquery("select * from win32_process where name='wscript.exe' and commandline like '%"&wscript.scriptname&"%'",,48)

for each objitem in colitems

set colitems=objWMIservice.execquery("select * from win32_process where name='wscript.exe' and commandline like '%"&wscript.scriptname&"%'",,48)
for each objitem in colitems
    if Instr(objitem.commandline,wscript.scriptname)<>0 and counter>1 then
        objshell.popup "already Same script is running",timeout
        exit sub
        do while true
            wscript.sleep 50000
            objshell.sendkeys "{F15}"
    end if
end sub

Usage Instructions & Notes:

  • Copy paste the Above vb script code in to a text file and save it has AntiLockingScript.vbs(File name could be anything, but extension should be .vbs)
  • Before trigger the actual automation, call/execute the script file in the automation solution.
  • This script is coded in such a way that, only one instance of the above vbscript will execute in the background regardless of multiple initiations of automation code.
  • This script creates a shell object in the background and runs infinite loop, without consuming much system resources, and avoids system from getting locked.
  • This script can also be used while running the automation solutions on Virtual machines (VMs)