Solved

Run shell script in silent mode

Posted on 2013-06-27
2
1,062 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 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

20 Experts available now in Live!

Get 1:1 Help Now