6
Answers

WMI and System.Management namespace - Enumerating classes

Andy Webster

Andy Webster

16y
8.6k
1

Hi

I am going a bit mad trying to overcome what seems to be a simple task.

I am trying to list the available WMI classes in code. I realise I can look these up in MSDN but need to enumerate them in code. I am trying to find the equivalent of the following vb script in c#

strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colClasses = objWMIService.SubclassesOf()
 
For Each objClass in colClasses
            WScript.Echo objClass.Path_.Class
Next

If I execute this using cscript I get exactly what I am after in c#. However, I am finding it impossible to create C# code to provide the same output. Any assistance would be very greatly appreciated

Regards

 

 

Answers (6)