Pages

Prevent System won't go to sleep state

How to control System so it won't go to sleep state?

We can achieve this by small code snippets developed by using VB Script.
   set wsc = CreateObject("WScript.Shell")
Do
        WScript.Sleep (1*1000)
        wsc.SendKeys ("{CAPSLOCK}")
        WScript.Sleep (2*1000)
        wsc.SendKeys ("{CAPSLOCK}")
        'Five minutes        WScript.Sleep(3*60*1000)
        wsc.SendKeys("{NUMLOCK}")
Loop
Here,
  • the Sleep() method will suspend the execution of the script for specified milliseconds.
  • SendKeys will do actions for specified function i.e., it will press the caps lock key for "{CAPSLOCK}" and press the Numlock key for {NUMLOCK}

In this way, our system will never go to sleep state as we are pressing keys in regular intervals.

Implementation in System:
  • Copy the above code snippet in the new editor and save it as .vbs extension.
  • Once the file saved successfully, double click the file then code started execution. And your system will never go to sleep state.
Now we see how to stop above running code execution.
  • Copy the below code snippet in the other new editor and save it as .vbs extension.
  • Once the file saved successfully, double click the file then code started execution. And your system is ready to go to sleep state according to your system settings.
' --- Define Object
    Set wmi = GetObject("winmgmts://./root/cimv2")

' --- Search and Destroy
    qry = "SELECT * FROM Win32_Process WHERE Name='wscript.exe' AND NOT " & _
    "CommandLine LIKE '%" & Replace(WScript.ScriptFullName, "\", "\\") & "%'"

    For Each p In wmi.ExecQuery(qry)
      p.Terminate
    Next

' --- Clean up
    Set wmi = Nothing ' Release the Application object
Once files are saved with .vbs extension it will save in below format:


VB Script Files
VB Script Files

Note:
It's better to save 2 files at same location.

Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.