1

I need to write a diagnostic utility in VBS which i will package in my windows application installer.

I want the utility to run silently when the user is installing the application.

I tried:

Set pingCXS = objShell.Run("tracert -h 9 webaddress", 0, True)

  Set pingCXSOutput = pingCXS.StdOut

  strpingCXSOutput = pingCXSOutput.ReadAll

but it returns only the error code not the whole ping information.

When i use run method it gives a command window pop up:

Any other method to traceRT the webaddress without windows popup?

Also using a batch file is not a good option for me, as i have to use some WMI queries in the utility, which will require admin rights in batch file...

Please help out

Hackoo
  • 18,337
  • 3
  • 40
  • 70

1 Answers1

0

Try this code :

Option Explicit
Dim ws,fso,TmpLogFile,Logfile,MyCmd,Webaddress,Param
Set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject") 
TmpLogFile = "TmpFile.txt"
LogFile = Left(Wscript.ScriptFullName,InstrRev(Wscript.ScriptFullName, ".")) & "log"
If fso.FileExists(LogFile) Then fso.DeleteFile LogFile
webaddress = "www.stackoverflow.com"
Param = "-h 9"
MyCmd = "Tracert " & Param & " " & Webaddress & " >> "& TmpLogFile &_
" & cmd /U /C Type " & TmpLogFile & " > " & LogFile & " & Del " & TmpLogFile & "" 
Call Run(MyCmd,0,True)
ws.run LogFile
'**********************************************************************************************
Function Run(StrCmd,Console,bWaitOnReturn)
    Dim ws,MyCmd,Result
    Set ws = CreateObject("wscript.Shell")
'A value of 0 to hide the MS-DOS console
    If Console = 0 Then
        MyCmd = "CMD /C " & StrCmd & ""
        Result = ws.run(MyCmd,Console,bWaitOnReturn)
        If Result = 0 Then
            MsgBox "Success"
        Else
            MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
        End If
    End If
'A value of 1 to show the MS-DOS console
    If Console = 1 Then
        MyCmd = "CMD /K " & StrCmd & ""
        Result = ws.run(MyCmd,Console,bWaitOnReturn)
        If Result = 0 Then
            MsgBox "Success"
        Else
            MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
        End If
    End If
    Run = Result
End Function
Hackoo
  • 18,337
  • 3
  • 40
  • 70