how to prevent auto lock in windows 7

1.9k views Asked by At

I am automating a process and automation will be running 24*7. Automation will be running on client system and that system automatically get locked after 10 mins because of this automation stopped.

I don't have permission to change the settings.

I want to prevent auto lock by generating event either mouse event or keystroke. Is it possible through JavaScript or Is there better way to achieve the same?

OS:Window 7

Any suggestion will be help.

2

There are 2 answers

0
SK. On

After doing bit of research on various forum I had figured out that we can keep system unlock with the help of below JavaScript code:

function fnPreventWinLock() {
    var wsc = new ActiveXObject('WScript.Shell');
    wsc.SendKeys ("{SCROLLLOCK}");
    wsc = null ;
}

Call this above function after certain amount of time (Say:5 mins) with window.setTimeout() function to keep system unlock.

0
Mr. V On

I have made a very simple and easy to use script(.bat) which disabled autolock by running the script in a console(cmd) window. If you want to stop the script, the user just need to close the console window.

:: SAVE this script as a .bat file and execute it to disable autolock   
@echo off
COLOR 0A
mode 69,9
title Stay Awake
echo Dim objResult > %temp%\stay_awake.vbs
echo Set objShell = WScript.CreateObject("WScript.Shell")    >> %temp%\stay_awake.vbs
echo Do While True >> %temp%\stay_awake.vbs
echo  objResult = objShell.sendkeys("{NUMLOCK}{NUMLOCK}") >> %temp%\stay_awake.vbs
echo  Wscript.Sleep (5000) >> %temp%\stay_awake.vbs
echo Loop >> %temp%\stay_awake.vbs
echo Start Time: %date% %time%
ECHO Please close this window to stop the Stay_Awake Script
echo.
cscript %temp%\stay_awake.vbs