方法一:模拟按键(简单有效)
Set WshShell = WScript.CreateObject("WScript.Shell")
Do While True
' 模拟按下F13键(无实际功能,避免干扰)
' 或者使用其他不常用的组合键
WshShell.SendKeys "{F13}"
' 等待一段时间(单位:毫秒)
WScript.Sleep 60000 ' 每分钟一次
Loop
方法二:移动鼠标(更隐蔽)
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim x, y
Do While True
' 获取当前鼠标位置
x = CreateObject("WScript.Shell").AppActivate("")
' 轻微移动鼠标(1像素)
CreateObject("WScript.Shell").Run "powershell -command ""Add-Type -AssemblyName System.Windows.Forms; [Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point([Windows.Forms.Cursor]::Position.X+1, [Windows.Forms.Cursor]::Position.Y+1)""", 0, True
' 等待时间
WScript.Sleep 30000 ' 每30秒一次
Loop
方法三:使用PowerShell命令(推荐)
Set WshShell = WScript.CreateObject("WScript.Shell")
Do While True
' 执行PowerShell命令重置屏幕超时
WshShell.Run "powershell -command ""$ts = (Get-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name ScreenSaveTimeOut).ScreenSaveTimeOut; if($ts -ne 0) { Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name ScreenSaveTimeOut -Value 0; Start-Sleep -Seconds 2; Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name ScreenSaveTimeOut -Value $ts }""", 0, True
' 模拟轻量级按键(Ctrl键)
WshShell.SendKeys "^"
WScript.Sleep 120000 ' 每2分钟一次
Loop
方法四:组合方案(最稳定)
' 防止锁屏脚本 - 多种方法组合
Option Explicit
Dim WshShell, lastMethod, counter
Set WshShell = CreateObject("WScript.Shell")
lastMethod = 0
counter = 0
' 设置屏幕保护时间为0(禁用)
WshShell.RegWrite "HKCU\Control Panel\Desktop\ScreenSaveTimeOut", "0", "REG_SZ"
WshShell.RegWrite "HKCU\Control Panel\Desktop\ScreenSaveActive", "0", "REG_SZ"
' 主循环
Do While True
counter = counter + 1
' 每30秒切换一种方法
Select Case lastMethod
Case 0
' 方法1:模拟NumLock切换
WshShell.SendKeys "{NUMLOCK}"
WshShell.SendKeys "{NUMLOCK}"
Case 1
' 方法2:模拟Ctrl键
WshShell.SendKeys "^"
Case 2
' 方法3:模拟Shift键
WshShell.SendKeys "+"
Case Else
' 方法4:轻微移动鼠标(通过PowerShell)
WshShell.Run "powershell -command ""[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point([System.Windows.Forms.Cursor]::Position.X+1, [System.Windows.Forms.Cursor]::Position.Y+1)""", 0, True
lastMethod = -1
End Select
lastMethod = lastMethod + 1
' 每10分钟显示状态(可选)
If counter Mod 20 = 0 Then
WScript.Echo "防止锁屏脚本运行中... " & Now()
End If
' 等待30秒
WScript.Sleep 30000
Loop
' 清理代码(不会执行到此处)
Sub CleanUp()
WshShell.RegWrite "HKCU\Control Panel\Desktop\ScreenSaveTimeOut", "600", "REG_SZ"
WshShell.RegWrite "HKCU\Control Panel\Desktop\ScreenSaveActive", "1", "REG_SZ"
End Sub
使用方法:
将代码保存为
.vbs 文件(如
noidle.vbs)
双击运行即可
要停止脚本,打开任务管理器结束
wscript.exe 进程
注意事项:
⚠️ 重要提示:
- 这些方法可能违反公司IT政策,请确保在授权环境下使用
- 长时间运行可能影响系统性能
- 某些安全软件可能标记为可疑行为
- 建议设置合理的间隔时间(30秒-2分钟)
- 完成任务后及时停止脚本
创建快捷方式(可选):
可以创建快捷方式并设置:
- 最小化运行:
wscript.exe //B yourscript.vbs
- 开机启动:将快捷方式放入启动文件夹
建议根据实际需求调整等待时间和使用的方法组合。