You can use the System.Manageme nt 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_opti ons stuff also.
using System.Manageme nt;
/// ----------------- Need class dedfinition...
int result;
result = 0;
string host;
host = "LOCALHOST" ;
ConnectionOptio ns Connect_options = new ConnectionOptio ns();
Connect_options .Username = user; // enter username
Connect_options .Password = password; // enter password
ManagementScope scope = new
ManagementScope ("\\\\"+host+"\ \root\\cimv2",C onnect_options) ;
scope.Options.E nablePrivileges = true;
scope.Connect() ;
System.Manageme nt.ObjectQuery oq = new System.Manageme nt.ObjectQuery( "SELECT
* FROM Win32_Operating System");
ManagementObjec tSearcher query1 = new ManagementObjec tSearcher(scope ,oq);
ManagementObjec tCollection queryCollection 1 = query1.Get();
foreach( ManagementObjec t mo in queryCollection 1 )
{
string[] ss={"6","0"};
mo.InvokeMethod ("Win32Shutdown ",ss);
Console.WriteLi ne(mo.ToString( ));
}
"A" <NO****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Anyone have any code to reboot from a C# app?