【问题标题】:How to keep the system awake by sending Keypresses using VBS script? [duplicate]如何通过使用 VBScript 发送按键来保持系统唤醒? [复制]
【发布时间】:2021-01-07 12:41:00
【问题描述】:

我有一台设备的待机超时时间非常低(2 分钟)。 所以我想构建一个 VBS 脚本,它会启动记事本并发送按键,以便系统保持清醒。

【问题讨论】:

标签: windows vbscript mouseevent simulation keyboard-events


【解决方案1】:

在网上论坛上摸了摸头,我想出了一个代码来反复写Hi。我希望它能造福于社区。​​p>

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

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

【讨论】:

  • 就个人而言,将脚本包含在一个允许将延迟值作为参数传递的函数中会更好地工作,如果需要,甚至可以从命令行传递。然而,正如过去的副本所示,有更简单的方法可以解决这个问题。
猜你喜欢
  • 2013-07-12
  • 1970-01-01
  • 1970-01-01
  • 2011-05-02
  • 1970-01-01
  • 1970-01-01
  • 2020-12-30
  • 2022-07-04
  • 2012-08-29
相关资源
最近更新 更多