Solved

Run shell script in silent mode

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

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 26

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

746 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

8 Experts available now in Live!

Get 1:1 Help Now