You can use the System.Management interfaces to reboot a machine. This uses
WMI (I think it stands for Windows Management Instrumentation ). This will
also allow you to reboot remote machines too if you wanted to.
Here's some code, may need some changes, I just copy/pasted from my code. If
the current user has permissions to reboot the machine, you can comment out
the connection_options stuff also.
using System.Management;
/// ----------------- Need class dedfinition...
int result;
result = 0;
string host;
host = "LOCALHOST";
ConnectionOptions Connect_options = new ConnectionOptions();
Connect_options.Username = user; // enter username
Connect_options.Password = password; // enter password
ManagementScope scope = new
ManagementScope("\\\\"+host+"\\root\\cimv2",Connec t_options);
scope.Options.EnablePrivileges = true;
scope.Connect();
System.Management.ObjectQuery oq = new System.Management.ObjectQuery("SELECT
* FROM Win32_OperatingSystem");
ManagementObjectSearcher query1 = new ManagementObjectSearcher(scope,oq);
ManagementObjectCollection queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 )
{
string[] ss={"6","0"};
mo.InvokeMethod("Win32Shutdown",ss);
Console.WriteLine(mo.ToString());
}
"A" <NO****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Anyone have any code to reboot from a C# app?