Windows 如何通过使用VBS脚本发送按键来保持系统处于唤醒状态?

Windows 如何通过使用VBS脚本发送按键来保持系统处于唤醒状态?,windows,vbscript,mouseevent,simulation,keyboard-events,Windows,Vbscript,Mouseevent,Simulation,Keyboard Events,我有一个设备的待机超时时间很低(2分钟)。 因此,我想构建一个VBS脚本,它将启动记事本并发送击键,这样系统就可以保持清醒。在在线论坛上挠头之后,我想出了一个代码来反复编写Hi。我希望这对社会有益 Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "notepad" WScript.Sleep 100 Dim x x = 1 set service = GetObject (

我有一个设备的待机超时时间很低(2分钟)。
因此,我想构建一个VBS脚本,它将启动记事本并发送击键,这样系统就可以保持清醒。

在在线论坛上挠头之后,我想出了一个代码来反复编写Hi。我希望这对社会有益

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad"
WScript.Sleep 100
Dim x
x = 1
set service = GetObject ("winmgmts:")
Function IsAppRunning(AppName)
    for Each Process in Service.Instancesof("Win32_Process")
        If UCase(Process.Name) = UCase(AppName) then
            IsAppRunning = True
            Exit function
        End If
    next
    IsAppRunning = False
End Function

While x < 1000 


AppName = "notepad.exe"

If IsAppRunning(AppName) then
WshShell.AppActivate "Notepad"
WshShell.SendKeys "H"
WScript.Sleep 5000
else
    Wscript.quit
End If

If IsAppRunning(AppName) then
WshShell.AppActivate "Notepad"
WshShell.SendKeys "i" 
WScript.Sleep 5000
else
    Wscript.quit
End If

x=x+1
Wend
Set WshShell=WScript.CreateObject(“WScript.Shell”)
WshShell.运行“记事本”
WScript.Sleep 100
暗x
x=1
设置服务=GetObject(“winmgmts:”)
函数IsAppRunning(AppName)
对于服务中的每个进程。Instancesof(“Win32_进程”)
如果UCase(Process.Name)=UCase(AppName),则
IsAppRunning=True
退出功能
如果结束
下一个
IsAppRunning=False
端函数
而x<1000
AppName=“notepad.exe”
如果正在运行(AppName),则
WshShell.app激活“记事本”
WshShell.SendKeys“H”
WScript.Sleep 5000
其他的
Wscript.quit
如果结束
如果正在运行(AppName),则
WshShell.app激活“记事本”
WshShell.SendKeys“i”
WScript.Sleep 5000
其他的
Wscript.quit
如果结束
x=x+1
温德

要停止脚本的执行,只需退出记事本。通过更改while循环计数,可以修改代码以运行更长/更短的持续时间。当前,该脚本将运行近3个小时,或者直到用户关闭记事本。很抱歉,我在这里没有问任何问题,只是提供了我所做的。

这是否回答了您的问题?是不睡觉的内在方式。是什么的内在方式?这只是VB.Net的一个端口。这是程序保持清醒的正确方法。就个人而言,如果将脚本封装在一个函数中,它可以将延迟值作为参数传入,甚至可以在需要时从命令行传入。然而,正如过去的副本所示,有更简单的方法来实现这一点。