PDA

View Full Version : Hide CMD window that script shows.



danfleetwood
09-12-2011, 11:51 AM
Thanks to Apps help (http://www.vbaexpress.com/forum/showthread.php?p=250418#post250418) on the below process to check if a server is alive with a ping my question now is how to hide the two cmd.exe windows that show.

I beleive the line in bold needs an argument to not show the window as per http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx (http://msdn.microsoft.com/en-us/library/d5fk67ky%28VS.85%29.aspx) I have tried changing it to "Set oExec = oShell.Exec(strCmd, 1)" but I get the error "Wrong number of arguments (Error 450)"

Any help is much appreciated.

Private Sub UserForm_Click()
Dim strComputer As String
strComputer1 = "server1"
strComputer2 = "server2"
If Not SystemOnline(strComputer1) Then
FTPService1.Caption = "Offline"
FTPService1.BackColor = vbRed
Else
FTPService1.Caption = "Online"
FTPService1.BackColor = vbGreen
End IfIf Not SystemOnline(strComputer2) Then
FTPService2.Caption = "Offline"
FTPService2.BackColor = vbRed
Else
FTPService2.Caption = "Online"
FTPService2.BackColor = vbGreen
End If
End Sub 'TestPing
'Determine if system is online
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

mancubus
09-13-2011, 04:31 AM
hi.
i think, you may adopt the following kb sample file to your case.

http://www.vbaexpress.com/kb/getarticle.php?kb_id=537

it seems instead of oShell.Exec, oShell.Run is used with a temporary file to store rthe result.

wsh.Run "%comspec% /c ipconfig > " & TempFil, 0, True