如何使用VBscript防止XP机器的自动锁定功能

时间:2010-12-16 06:04:57

标签: vbscript automation

机器在自动化脚本运行时被锁定,这是因为不同脚本之间存在很长的间隔(由于某些原因,这是必需的)。我想避免这种自动锁定功能。问题是,根据安全策略,我们无法从控制面板禁用此功能。还有其他方法可以保持系统解锁吗?

11 个答案:

答案 0 :(得分:18)

我这样做了......它快速发送2个SCROLLLOCK键,因此它不会干扰(好吧,不管怎么说都不严重)任何应用程序。它每隔60秒就会这样做....干杯!

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

答案 1 :(得分:6)

我认为您可以通过定期发送按键来暂停锁定,因此我建议您查看WScript.SendKeys。然后把它放在一个睡眠循环中,让它定期发送。

请注意您发送的密钥,以免影响其他任何密钥。

答案 2 :(得分:2)

我使用了一对文件......

第一个文件(Keep_Awake__start.vbs)保持唤醒/解锁状态。当您想要恢复正常过程时,第二个文件(Keep_Awake__end.vbs)可以方便地终止该过程。

第一个文件......

' 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

第二个档案......

' 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

这些文件既可以从常规文本编辑器创建,也可以存储在任何地方(如桌面)。使用.vbs文件扩展名保存文件后,该文件是可执行文件。因此,您只需双击文件图标即可开始或结束(取决于您双击哪个文件)。

您可以将Keep_Awake__start.vbs存储在Windows Startup文件夹中,以便在您登录后立即启动。

答案 3 :(得分:1)

最简单的解决方案是打开mp3或视频文件并在Windows媒体播放器中连续播放(使用重复功能并将播放器中的音量静音)。通过这种方式,屏幕保护程序永远不会到来或系统永远不会锁定。

答案 4 :(得分:0)

如果这是在运行自动化套件时,请使用自动化套件每隔一段时间做一次鼠标抽搐。我发现效果很好的是如果你有自己的自定义睡眠功能,并且作为睡眠功能的一部分,你会抽搐鼠标。用于脚本之间的长时间间隔。

答案 5 :(得分:0)

使用以下VB脚本代码让您的机器解锁:

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"

干杯!!

答案 6 :(得分:0)

我已经尝试过shell脚本并使用任务计划程序安排鼠标移动的模拟 - 但是我发现这是最好的。 +1简洁。它会自动将鼠标移动到移动的像素,因此屏幕不会自动锁定(如果需要,您可以选择配置它)

参考: 自动鼠标移动器 - http://www.murgee.com/auto-mouse-mover/

答案 7 :(得分:0)

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

我们可以使用此代码来防止窗口再次解锁。

答案 8 :(得分:0)

我这样做了

(外部循环=声明变量)

'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

(内部程序)

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

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

(内循环):

        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

所以 - 基本上这个代码会在每个循环间隔移动鼠标1 px leftup和1 px rightdown lor。您可以声明任何其他值,但我发现此鼠标移动不会打扰用户。

答案 9 :(得分:0)

如果有人需要带有条件的声明

#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

答案 10 :(得分:0)

我制作了一个非常简单易用的脚本(.bat),该脚本通过在控制台(cmd)窗口中运行脚本来禁用自动锁定。如果要停止脚本,则用户只需关闭控制台窗口。 #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