使用VBScript静默运行EXE

时间:2019-10-23 08:56:37

标签: vbscript

我创建了一个脚本,该脚本使用程序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

0 个答案:

没有答案