vbscript - 使用 VBScript 静默运行 EXE
问题描述
我创建了一个脚本,该脚本使用程序检查空闲时间MousePos.exe
并将响应推送回自身,以确定是否有任何鼠标移动。这一切都很好,但是每次MousePos.exe
运行它都会在屏幕上闪烁,我想隐藏它。我不知道该怎么做,我希望它会很简单。
有人建议我需要使用WshShell
对象的Run
方法而不是WshScriptExec
对象,但我不知道如何执行此操作,并且仍然读取来自 EXE 的响应。
Function execStdOut(cmd)
Dim goWSH : Set goWSH = CreateObject("WScript.Shell")
Dim aRet: Set aRet = goWSH.Exec(cmd)
execStdOut = aRet.StdOut.ReadAll()
End Function
'wait 2 seconds for things to calm now
WScript.Sleep 2000
'get initial Mouse XY
MPOS = execStdOut("cmd /c C:\Windows\MousePos.exe")
WScript.Sleep 10000 '10 seconds
'set initial idle counter
Idle = 0
Do While forever = 0
OLD = MPOS
MPOS = execStdOut("cmd /c C:\Windows\MousePos.exe")
If OLD = MPOS Then
Idle = Idle + 1
If idle = 12 Then '12 x 10 seconds for 2 minute timeout
idle = 0
Set objShell = WScript.CreateObject("WScript.Shell")
objshell.Run "C:\Windows\IERestart_countdown.hta", 1, True
End If
Else
idle = 0
End If
WScript.Sleep 10000 ' 10 seconds
Loop
解决方案
推荐阅读
- python - 在 for 循环中添加了 else 语句,现在即使 if 为 true,也只会打印 else 部分
- qt - QQuickPaintedItem paint() 报错Timers 无法从另一个线程停止,这似乎导致子线程死循环?
- azure - 如何将消息推送到 azure 服务总线并触发 azure 函数来记录它看到消息
- ios - 返回多个字符串字符
- json - 在 JSON-LD 中的对象类型中嵌套 Schema.org 属性类型的正确方法是什么
- c - 为什么这个 Shaker Sort 代码在 C 中不起作用
- ruby - 将 File.readlines[n] 分配给变量
- php - 提交后保持匹配数组键的复选框状态
- html - Angular 8:错误类型错误:无法读取未定义的属性“无效”
- python - 如何按频率对字典进行排序并仅打印前 10 个结果?