Updated: 16/05/2004; 22:46:10.
Hannes 'Shorty' Decorte's Radio Weblog
Learning .Net and the Experiences doing so


maandag 24 november 2003

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    comment []

© Copyright 2004 Hannes 'Shorty' Decorte.
 
November 2003
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Oct   Dec



Other .Net Bloggers

Bart De Smet
Jan Tielens
Patrick Verbruggen
Patrick Tisseghem
Tom van de Kerkhof's Bloggings
Tom's Corner
Yves Hanoulle

Aggregated Feeds

Belgian .NET Bloggers