|The WMI support in .NET is superb. The best way to do this is to create a new project, then open your Server explorer (the "Server" tab next to the "Toolbox" in the default VS.NET installation) add your computer unders Servers (if it isn't already), then drill-down the find the Management Classes node. If you don't see them, download the setup at http://go.microsoft.com/fwlink/?LinkId=3353[^].
Now find the Operating Systems node. Right-click and click Generate Managed Class. Now you have the Win32_OperatingSystem class encapsulated in a .NET class you can use in many ways! This will have several methods for what you need, such as a
You can then, for example, reboot a named machine like so:
ManagementScope scope = new ManagementScope(
Sample.ROOT.CIMV2.OperatingSystem.OperatingSystemCollection systems =
Sample.ROOT.CIMV2.OperatingSystem.GetInstances(scope, null, null);
foreach (Sample.ROOT.CIMV2.OperatingSystem system in systems)
system.Reboot();Sample is the just the namespace I used to write the example code. The
Sample.ROOT.CIMV2 namespaces and the classes and nested classes therein where generated from the step above.
-----BEGIN GEEK CODE BLOCK-----
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----