Verfügbarkeit eines Rechners im Netzwerk mit einem Ping prüfen
Das folgende Visual Basic Script soll zeigen, wie Sie innerhalb eines Visual Basic Scriptes mit Hilfe eines Pings (ICMP Echo Request) überprüfen können ob ein bestimmter Rechner im Netzwerk verfügbar ist.
Option Explicit
' Declaration of global variable
Dim strHostname
' Set parameter
strHostname = "www.gtkdb.de"
' Use function Ping() to check online status
If Ping(strHostname) Then
MsgBox(strHostname & " is reachable.")
Else
MsgBox(strHostname & " not reachable.")
End If
' Quit Visual Basic Script
WScript.Quit()
' ====================================================================
' === Functions ===
' ====================================================================
' Function Ping()
Function Ping(strHost)
' Declaration of local variables
Dim objPing
Dim objReturnStatus
Dim bReturn
' Create ping object
Set objPing = GetObject("winmgmts:{ImpersonationLevel=Impersonate}").ExecQuery("Select * From Win32_PingStatus Where address='" & strHost & "'")
' Check return status of ping
For Each objReturnStatus In objPing
If IsNull(objReturnStatus.StatusCode) Or objReturnStatus.StatusCode <> 0 Then
bReturn = False
Else
bReturn = True
End If
' Deallocate return status object
Set objReturnStatus = Nothing
Next
' Deallocate ping object
Set objPing = Nothing
' Return result
Ping = bReturn
End Function
' Declaration of global variable
Dim strHostname
' Set parameter
strHostname = "www.gtkdb.de"
' Use function Ping() to check online status
If Ping(strHostname) Then
MsgBox(strHostname & " is reachable.")
Else
MsgBox(strHostname & " not reachable.")
End If
' Quit Visual Basic Script
WScript.Quit()
' ====================================================================
' === Functions ===
' ====================================================================
' Function Ping()
Function Ping(strHost)
' Declaration of local variables
Dim objPing
Dim objReturnStatus
Dim bReturn
' Create ping object
Set objPing = GetObject("winmgmts:{ImpersonationLevel=Impersonate}").ExecQuery("Select * From Win32_PingStatus Where address='" & strHost & "'")
' Check return status of ping
For Each objReturnStatus In objPing
If IsNull(objReturnStatus.StatusCode) Or objReturnStatus.StatusCode <> 0 Then
bReturn = False
Else
bReturn = True
End If
' Deallocate return status object
Set objReturnStatus = Nothing
Next
' Deallocate ping object
Set objPing = Nothing
' Return result
Ping = bReturn
End Function
Dieser Eintrag wurde am 22.12.2012 erstellt.
Direkter Link zu dieser Seite: http://www.gtkdb.de/index_29_2025.html
[ Zur Startseite ] [ Zur Kategorie ]
© 2004-2021 by Georg Kainzbauer