首页 > 解决方案 > 使用 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

标签: vbscript

解决方案


推荐阅读