How to use a WMI class ? 
Author Message
 How to use a WMI class ?

I want to use WMI classes with .NET.  I saw an example
with ManagementObject:

ManagementObject disk =
new ManagementObject("win32_logicaldisk.deviceid=\"C:\"");

It's ok and it works.

Now I want to use the WMI class "Win32_Processor".
If I instantiate an ManagementObject like this:

ManagementObject proc = new ManagementObject
("Win32_Processor");

I get an error!

How should I instantiate an ManagementObject if I want to
use the Win32_Processor class ?

Thanks!



Tue, 12 Apr 2005 18:40:58 GMT  
 How to use a WMI class ?
Try this example:

        // instantiate the management class
        ManagementClass mc = new ManagementClass("Win32_Processor");
        Console.WriteLine( mc.ClassPath );

        // enumerate the instances
        foreach (ManagementObject mo in mc.GetInstances()) {
            Console.WriteLine(mo);
        }

        // look up a particular instance, bind and display
        ManagementObject mo2 = new
ManagementObject("Win32_Processor.DeviceID='CPU0'");
        mo2.Get();
        Console.WriteLine(mo2);

/Fredrik


Quote:

> I want to use WMI classes with .NET.  I saw an example
> with ManagementObject:

> ManagementObject disk =
> new ManagementObject("win32_logicaldisk.deviceid=\"C:\"");

> It's ok and it works.

> Now I want to use the WMI class "Win32_Processor".
> If I instantiate an ManagementObject like this:

> ManagementObject proc = new ManagementObject
> ("Win32_Processor");

> I get an error!

> How should I instantiate an ManagementObject if I want to
> use the Win32_Processor class ?

> Thanks!



Tue, 12 Apr 2005 23:04:01 GMT  
 How to use a WMI class ?
Hi,

Please check this tool which is in the .Net Framework SDK.
Management Strongly Typed Class Generator (Mgmtclassgen.exe)

The Management Strongly Typed Class Generator enables you to quickly
generate an early-bound managed class for a specified Windows Management
Instrumentation (WMI) class. The generated class simplifies the code you
must write to access an instance of the WMI class.

I hope this helps. If you have any questions, please reply to this post.

Best Regards,

Jun Su
Microsoft Support

---
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| Content-Class: urn:content-classes:message


| Subject: How to use a WMI class ?
| Date: Fri, 25 Oct 2002 03:40:58 -0700
|
|
| I want to use WMI classes with .NET.  I saw an example
| with ManagementObject:
|
| ManagementObject disk =
| new ManagementObject("win32_logicaldisk.deviceid=\"C:\"");
|
| It's ok and it works.
|
| Now I want to use the WMI class "Win32_Processor".
| If I instantiate an ManagementObject like this:
|
| ManagementObject proc = new ManagementObject
| ("Win32_Processor");
|
| I get an error!
|
| How should I instantiate an ManagementObject if I want to
| use the Win32_Processor class ?
|
| Thanks!
|
|



Thu, 14 Apr 2005 20:22:55 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. WMI - WMI Login Cotrol causes exception when destroying

2. which WMI class for installed software

3. WMI - how to use managament class methods

4. NetConnectionID using WMI?

5. Can WMI be used to get network computers?

6. Shutdown using WMI

7. help on using WMI (Windows Management Instrumentation)

8. Howto enumerate machines in a domain using WMI

9. Reference problem when using VB classes with C# classes

10. Using unmanaged class/data structure in managed class

11. Using unmanaged nested classes of a managed class

12. How Remove a Class Once Added Using Class Wizard

 

 
Powered by phpBB® Forum Software