using System; using System.Management; using System.ComponentModel; using System.Runtime.InteropServices; // Shutdown or Reboot a system using WMI (management classes) public class Wmis { private System.Management.ManagementObject o; public static void Main() { Wmis wm = new Wmis(); ManagementPath path = new ManagementPath( ); path.Server = "SomeMachineName"; // Your machine name path.NamespacePath = @"root\CIMV2"; /* Check your systems BOOT.INI file for : [operating systems] multi(0)disk(0)rdisk(0)partition(1)\WINNT="Microsoft Windows 2000 Professional" /fastdetect and add the info into the RelativePath property. */ path.RelativePath = @"Win32_OperatingSystem.Name=""Microsoft Windows 2000 Professional|C:\\WINNT|\\Device\\Harddisk0\\Partition1"""; wm.o = new ManagementObject(path); ManagementBaseObject inParams = null; // Turn on required privileges to reboot/shutdown etc. bool EnablePrivileges = wm.o.Scope.Options.EnablePrivileges; wm.o.Scope.Options.EnablePrivileges = true; // Use 'Shutdown' method to shutdown a system. ManagementBaseObject outParams = wm.o.InvokeMethod("Reboot", inParams, null); wm.o.Scope.Options.EnablePrivileges = EnablePrivileges; // Console.WriteLine ((System.UInt32)(outParams.Properties["ReturnValue"].Value)); wm.o.Dispose(); } }
using System.Management;
using System.ComponentModel;
using System.Runtime.InteropServices;
// Shutdown or Reboot a system using WMI (management classes)
public class Wmis {
private System.Management.ManagementObject o;
public static void Main() {
Wmis wm = new Wmis();
ManagementPath path = new ManagementPath( );
path.Server = "SomeMachineName"; // Your machine name
path.NamespacePath = @"root\CIMV2";
/* Check your systems BOOT.INI file for :
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINNT="Microsoft Windows 2000 Professional" /fastdetect
and add the info into the RelativePath property.
*/
path.RelativePath = @"Win32_OperatingSystem.Name=""Microsoft Windows 2000
Professional|C:\\WINNT|\\Device\\Harddisk0\\Partition1""";
wm.o = new ManagementObject(path);
ManagementBaseObject inParams = null;
// Turn on required privileges to reboot/shutdown etc.
bool EnablePrivileges = wm.o.Scope.Options.EnablePrivileges;
wm.o.Scope.Options.EnablePrivileges = true;
// Use 'Shutdown' method to shutdown a system.
ManagementBaseObject outParams = wm.o.InvokeMethod("Reboot", inParams, null);
wm.o.Scope.Options.EnablePrivileges = EnablePrivileges;
// Console.WriteLine ((System.UInt32)(outParams.Properties["ReturnValue"].Value));
wm.o.Dispose();
}
}