Scriptorium

us fr nl




VBA : Internet: Ping a computer in VBA using WMI   nl


Options: Save as PDF | Save attached file | Toggle line numbers

Details:

Type: function
Added By: Rembo
Short Description:
Windows Management Instrumentation (WMI) provides a uniform interface for any local or remote applications or scripts that obtain management data from a computer system, a network, or an enterprise. Information such as a computer name, logged in user and even process data can be easily retrieved using any script language that supports ActiveX objects. 
Notes:
With the Scripting API for WMI, you can develop quick, simple scripts or complex Microsoft Visual Basic management applications. Scripting gives you the same capability of getting information or of configuring most objects in an enterprise as you would have through a C++ or C# application. 

Note 1: you cannot write a WMI provider in script or Visual Basic.
Note 2: Depending on your version of Windows the WMI classes and objects vary in features and functionality.
Added: Feb 12 2009 at 11:37 AM
Modified: Feb 12 2009 at 11:38 AM
Related URLs


Usage:

Run the routine TestPing to see the result of a ping to scriptorium.serve-it.nl


Code:

Formatted | Unformatted
  1. Function sPing(sHost) As String
  2.  
  3. Dim oPing As Object, oRetStatus As Object
  4.  
  5. Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
  6. ("select * from Win32_PingStatus where address = '" & sHost & "'")
  7.  
  8. For Each oRetStatus In oPing
  9. If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
  10. sPing = "Status code is " & oRetStatus.StatusCode
  11. Else
  12. sPing = "Pinging " & sHost & " with " & oRetStatus.BufferSize & " bytes of data:" & Chr(10) & Chr(10)
  13. sPing = sPing & "Time (ms) = " & vbTab & oRetStatus.ResponseTime & Chr(10)
  14. sPing = sPing & "TTL (s) = " & vbTab & vbTab & oRetStatus.ResponseTimeToLive
  15. End If
  16. Next
  17. End Function
  18.  
  19. Sub TestPing()
  20. MsgBox sPing("scriptorium.serve-it.nl")
  21. End Sub



User comments :

Add a new comment   Back to Top
Atom Feed
Contact | About This Application | Scriptorium Website