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
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