How to prevent auto-locking feature of an XP machi

2019-01-23 07:21发布

问题:

machine get locked during the automation script run-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?

回答1:

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.



回答2:

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


回答3:

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.



回答4:

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.



回答5:

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.



回答6:

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



回答7:

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/



回答8:

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.



回答9:

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.