none
VBScript Silently Run EXE RRS feed

  • Question

  • Hi Guys,

    Fairly new / basic at VBScripting (would usually leverage powershell but for this customer i cant)

    I have knocked up a VB script which runs through to check Mouse movement using an executable and feeds back. If no movement it does something.

    Everything works apart from when the "MousePos.exe" runs every 10 seconds you see it flash for a milisecond on the screen and i want to hide this. I thought the "/C" would get rid of this but doesnt. Any ideas most appreciated!.

    So in a nutshell i want to be able to run "MousePos.exe" completely silently.

    Thanks in advance!

    Script below:

    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


    • Edited by c2wak Tuesday, October 22, 2019 1:47 PM
    Tuesday, October 22, 2019 1:46 PM

Answers

  • Use the WshShell object's Run method rather than the WshScriptExec object. (The WshScriptExec object will always display a console because it provides access to the output and error streams, which don't exist without a console.)


    -- Bill Stewart [Bill_Stewart]

    Tuesday, October 22, 2019 1:49 PM
    Moderator

All replies

  • Use the WshShell object's Run method rather than the WshScriptExec object. (The WshScriptExec object will always display a console because it provides access to the output and error streams, which don't exist without a console.)


    -- Bill Stewart [Bill_Stewart]

    Tuesday, October 22, 2019 1:49 PM
    Moderator
  • Thanks Bill so simply changing the following will prevent the window?

    Function execStdOut(cmd)
      Dim goWSH : Set goWSH = CreateObject( "WScript.Run" ) 
      Dim aRet: Set aRet = goWSH.exec(cmd)
      execStdOut = aRet.StdOut.ReadAll()
    End Function

    <section>

    Asked by:

    0
    Points
    c2wak
    Joined Apr 2009

    1

    </section>
    <section>

    VBScript Silently Run EXE RRS feed

    • Question

    • Question
      You cannot vote on your own post
      0

      Hi Guys,

      Fairly new / basic at VBScripting (would usually leverage powershell but for this customer i cant)

      I have knocked up a VB script which runs through to check Mouse movement using an executable and feeds back. If no movement it does something.

      Everything works apart from when the "MousePos.exe" runs every 10 seconds you see it flash for a milisecond on the screen and i want to hide this. I thought the "/C" would get rid of this but doesnt. Any ideas most appreciated!.

      So in a nutshell i want to be able to run "MousePos.exe" completely silently.

      Thanks in advance!

      Script below:

      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
    </section>
    <section>

    Asked by:

    0
    Points
    c2wak
    Joined Apr 2009

    1

    </section>
    <section>

    VBScript Silently Run EXE RRS feed

    • Question

    • Question
      You cannot vote on your own post
      0

      Hi Guys,

      Fairly new / basic at VBScripting (would usually leverage powershell but for this customer i cant)

      I have knocked up a VB script which runs through to check Mouse movement using an executable and feeds back. If no movement it does something.

      Everything works apart from when the "MousePos.exe" runs every 10 seconds you see it flash for a milisecond on the screen and i want to hide this. I thought the "/C" would get rid of this but doesnt. Any ideas most appreciated!.

      So in a nutshell i want to be able to run "MousePos.exe" completely silently.

      Thanks in advance!

      Script below:

      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
    </section>
    Tuesday, October 22, 2019 2:58 PM
  • Correct. Use the WshShell object's Run method instead of the WshScriptExec object.

    -- Bill Stewart [Bill_Stewart]


    Tuesday, October 22, 2019 3:07 PM
    Moderator
  • The shell has two method - Run and Exec. Use Run instead of EXE,

    Look at the docs for the shell object. Since you do not know VBS I recommend using PowerShell as it will be with us for a long time and VBS will disappear soon.  Microsoft has already purged almost all documentation on WSH and VBS from their sites.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/3cabb703-1d1e-4ca1-a670-a1ab55d88d98/vbscript-wscriptshellrun?forum=vbgeneral


    \_(ツ)_/

    Tuesday, October 22, 2019 3:39 PM