WMI - Windows Management Instrumentation
I've been doing some WMI lately with the managmentobject classes in the .Net Framework. Goal is creating a small app so the network admin could easelly monitor, terminate and start-up processes remote.
You can do a lot with the System.Net and System.Diagnostics namespace, but many members (System.Diagnostics.Process) are not available for remote processes.
Below you find a code snippet to get detailed information on a process(remote or local). Be aware that you need sufficient security privileges to be able to view remote process properties.
Dim lStruct_WinProcInfo As New Struct_WinProcInfo Dim mo As ManagementObject Dim lms_scope As ManagementScope = New ManagementScope("//" & as_IpAddress & "/root/cimv2") Dim lm_oq As System.Management.ObjectQuery = New System.Management.ObjectQuery( _ "SELECT * FROM Win32_Process WHERE ProcessID = " & CType(ai_ProcessId, String)) Dim lmoEnumerator As ManagementObjectCollection.ManagementObjectEnumerator
lms_scope.Connect()
Dim lm_objsearchquery As ManagementObjectSearcher = New ManagementObjectSearcher(lms_scope, lm_oq)
Dim lcol_queryCollection As ManagementObjectCollection = lm_objsearchquery.Get()
For Each mo In lcol_queryCollection Exit For Next
'Puts the info in a structure for easy access lStruct_WinProcInfo = uf_PutProcessInfoInStruct(mo)
Return lStruct_WinProcInfo
Process properties can be retrieved from "mo" as follow :
mo.GetPropertyValue("Description")
For a complete list of properies see : Win32_Process
9:24:36 PM
|