开发者

How to prevent auto-locking feature of an XP machine using VBscript

machine get locked during the automation script r开发者_开发百科un-time , this is because there is a long interval between different scripts that(this is required for some reasons) . I want to avoid this auto locking feature. The problem is, as per security policies we cannot disable this feature from control panel. Is there any other way to keep the system unlocked?


I did this...It sends 2 SCROLLLOCK Keys, quickly, so it wont interfere (well, not anything serious anyways) with any applications. It does this every 60 seconds....Cheers!

set wsc = CreateObject("WScript.Shell")
Do
WScript.Sleep (60*1000)
wsc.SendKeys ("{SCROLLLOCK 2}")
Loop

To stop it, open taskmanager and terminate the wscript.exe process. (If there are multiple, use the Command Line column to figure out which process)


I'd think that you could halt the locking by sending a keypress at regular intervals, so I'd suggest looking at WScript.SendKeys. Then put that in a loop with a sleep to make it send it regularly.

Just be careful about what key you're sending so you don't affect anything else though.


I use a pair of files...

The first file (Keep_Awake__start.vbs) keeps things awake/unlocked. The second file (Keep_Awake__end.vbs) conveniently terminates the process when you want to go back to a normal proces.

The first file...

' Keep_Awake__start.vbs
' Graham Edwards

' Typical stored in Start Menu 
'
' Use Keep_Awake__start.vbs to keep the computer from inactivity-based lockouts.
' Use Keep_Awake__end.vbs to remove Keep_Awake__start.vbs

' Largely pulled from st0le response
' Http://stackoverflow.com/questions/4457907/how-to-prevent-auto-locking-feature-of-an-xp-machine-using-vbscript

' --- Define Object
    set wsc = CreateObject("WScript.Shell")

' --- Loop every so many minutes and change the scroll lock setting 
    Do
        ' Wait for ~2 minutes
        WScript.Sleep (2*60*1000)
        wsc.SendKeys ("{SCROLLLOCK 2}")
    Loop

The second file...

' Keep_Awake__end.vbs
' Graham Edwards

' Use Keep_Awake__start.vbs to keep the computer from inactivity-based lockouts.
' Use Keep_Awake__end.vbs to remove Keep_Awake__start.vbs

' Largely pulled from Ansgar Wiechers response
' http://stackoverflow.com/questions/22324899/kill-a-vbscript-from-another-vbscript

' --- 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

The files can both be created from a regular text editor and stored anywhere (like your desktop). Once you save the file with a .vbs file extension, it is executable. So, you just have to double click on the file icon to get things to start or end (depending on which file you double click).

You could store the Keep_Awake__start.vbs in the Windows Startup folder, so it launches as soon as you log in.


The simplest solution that works is to open a mp3 or video file and play it continuously in windows media player (use the repeat feature and mute the volume in the player). In this way the screensaver never comes or the system never locks.


If this is while running your automation suite, then use your automation suite to do a mouse twitch every so often. What I find works well is if you have your own custom sleep function, and as part of your sleep function, you twitch the mouse. Use this for your long interval between scripts.


Use the following VB script code to keep your machine unlocked:

Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite "HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Control Panel\Desktop\ScreenSaverIsSecure", "0" , "REG_SZ"
Wscript.Echo "Your machine remains unlocked"

Cheers!!


I have tried the shell scripts and scheduling the simulation of mouse movements with task Scheduler - but here's what I found was the BEST of the lot. +1 for its simplicity. It automatically moves the mouse to a shifted pixel, so the screen does not auto-lock(though you have options to configure this, should the need be)

Reference: Auto Mouse Mover - http://www.murgee.com/auto-mouse-mover/


Set wshShell =wscript.CreateObject("WScript.Shell")
do
  wscript.sleep 55000
  wshshell.sendkeys "{SCROLLLOCK}"
loop

We can use this code to prevent window to unlock again.


I've done it this way

(outside loop = declared variable)

'For 64 bit Excel.
Private Declare PtrSafe Function SetCursorPos Lib "user32" _
                        (ByVal x As Long, _
                        ByVal y As Long) As Long
Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

'For 32 bit Excel.
Private Declare Function SetCursorPos Lib "user32" _
                        (ByVal x As Long, _
                        ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long


 ' default variable
 private mousecounter as integer

(inside procedure)

Dim llCoord As POINTAPI
Dim activeXMousePos As Integer
Dim activeYMousePos As Integer

GetCursorPos llCoord
activeXMousePos = llCoord.Xcoord
activeYMousePos = llCoord.Ycoord

(inside loop):

        If mousecounter <= 2 Then
            SetCursorPos activeXMousePos - 1, activeYMousePos - 1
            mousecounter = mousecounter + 1
        End If

        If mousecounter > 2 Then
            SetCursorPos activeXMousePos + 2, activeYMousePos + 2
            mousecounter = 0
        End If

So - basically this code moves mouse 1 px leftup and 1 px rightdown lor each loop interval. You can declare any other values but I've found that this mouse move don't bother users.


if anyone needs the declarations with conditions

#If vba7 and win64 then

'For 64 bit Excel.
Private Declare PtrSafe Function SetCursorPos Lib "user32"  (ByVal x As Long,  ByVal y As Long) As Long
Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long


#Else

'For 32 bit Excel.
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long,  ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

#End If


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. #disable_autolock_stackoverflow_mr_v

 :: 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜