usetheforce2
06-12-2003, 10:27 AM
hello all,
WMI is a fantastic tool to use when you want to do general or advanced tasks with standard or third party managed system objects. WMI allows us to automate mundane task or monitor network clients and services for potentially harmful events. Here’s a simple example (that was just posted in the API forum) to terminate all running Internet Explorer or Netscape processes running on a machine.
Private Sub Terminate_All_IE()
Dim WMIObject As Object
Dim WMIObjectSet As Object
' connect to WMI
Set WMIObjectSet = GetObject("WinMgmts:").execquery("select * from Win32_process where name='IEXPLORE.EXE'")
For Each WMIObject In WMIObjectSet
' terminate any found "IEXPLORE.EXE" processes
If WMIObject.Terminate = 0 Then
Debug.Print "Process terminated"
End If
Next
End Sub
Private Sub Command1_Click()
Terminate_All_IE
End Sub
Try doing this with the Windows Win32 API and see if you can do it in the same lines of code. Now you can appreciate the power WMI exposes when we want to deal with managed system objects.
If you’re interested in learning some more on the subject, I put together a small tutorial that describes the basic concepts of WMI and how to work with it. I put this together rather quickly, so if you find anything is unclear or just plain stupid, let me know and I’ll fix’r up.
Enjoy, Regan
WMI is a fantastic tool to use when you want to do general or advanced tasks with standard or third party managed system objects. WMI allows us to automate mundane task or monitor network clients and services for potentially harmful events. Here’s a simple example (that was just posted in the API forum) to terminate all running Internet Explorer or Netscape processes running on a machine.
Private Sub Terminate_All_IE()
Dim WMIObject As Object
Dim WMIObjectSet As Object
' connect to WMI
Set WMIObjectSet = GetObject("WinMgmts:").execquery("select * from Win32_process where name='IEXPLORE.EXE'")
For Each WMIObject In WMIObjectSet
' terminate any found "IEXPLORE.EXE" processes
If WMIObject.Terminate = 0 Then
Debug.Print "Process terminated"
End If
Next
End Sub
Private Sub Command1_Click()
Terminate_All_IE
End Sub
Try doing this with the Windows Win32 API and see if you can do it in the same lines of code. Now you can appreciate the power WMI exposes when we want to deal with managed system objects.
If you’re interested in learning some more on the subject, I put together a small tutorial that describes the basic concepts of WMI and how to work with it. I put this together rather quickly, so if you find anything is unclear or just plain stupid, let me know and I’ll fix’r up.
Enjoy, Regan