Solved

Run shell script in silent mode

Posted on 2013-06-27
2
1,086 Views
Last Modified: 2013-07-04
Does anyone know how to chang the code below t run in silent mode and not pop up the window during the ping event?

Function SystemOnline(ByVal ComputerName As String)

Dim oShell, oExec As Variant
Dim strText, strCmd As String
 
strText = ""
strCmd = "ping -n 3 -w 1000 " & ComputerName
Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.Exec(strCmd)
 
Do While Not oExec.StdOut.AtEndOfStream
    strText = oExec.StdOut.ReadLine()
    If InStr(strText, "Reply") > 0 Then
        SystemOnline = True
        Exit Do
    End If
Loop

End Function
0
Comment
Question by:SweetingA
  • 2
2 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39281872
The short answer is you can't, Shell.Exec can't be hidden, only Shell.Run supports that feature, the problem is you can't use Shell.Run to return info.
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39282135
For the longer answer...
You can direct the output from Shell.Run to a text file and parse it from there:
Option Explicit

Function SystemOnline(ByVal ComputerName As String) As Boolean

    Dim oFSO As Object, oShell As Object
    Dim oTextFile As Variant
    Dim strName As String, strTempFile As String, strText As String, strcomspec As String

    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oShell = CreateObject("Wscript.Shell")
    strcomspec = oShell.ExpandEnvironmentStrings("%comspec%")
    strName = oFSO.GetTempName
    strTempFile = strName
    oShell.Run strcomspec & " /c ping -n 3 -w 1000 " & ComputerName & " > " & strTempFile, 0, True
    Set oTextFile = oFSO.OpenTextFile(strTempFile, 1)
    Do While oTextFile.AtEndOfStream <> True
        strText = oTextFile.ReadLine
        If InStr(strText, "Reply") > 0 Then
            SystemOnline = True
            Exit Do
        End If
    Loop
    oTextFile.Close
    oFSO.DeleteFile (strTempFile)
End Function

Open in new window

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
You may have a outside contractor who comes in once a week or seasonal to do some work in your office but you only want to give him access to the programs and files he needs and keep privet all other documents and programs, can you do this on a loca…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now