Thanks..
[DllImport("User32.dll")]
public static extern bool ExitWindowsEx(uint uFlag, long lReason);
...
ExitWindowsEx(2, // 2 for EWX_REBOOT
0);
...
--
Robert Jeppesen
MindCom AB
"Diego" <die...@amdocs.com> wrote in message news:710601c1ee91$92f20e10$a5e62ecf@tkmsftngxa07...
System.Management.ManagementScope ms = new
System.Management.ManagementScope
(\\\\LocalHost\\root\\cimv2);
ms.Options.EnablePrivileges = true;
//Query remote computer across the connection
System.Management.ObjectQuery oq = new
System.Management.ObjectQuery("SELECT * FROM
Win32_OperatingSystem");
ManagementObjectSearcher query1 = new
ManagementObjectSearcher(ms,oq);
ManagementObjectCollection queryCollection1 =
query1.Get();
foreach( ManagementObject mo in queryCollection1 )
{
string[] ss={"2","0"};
mo.InvokeMethod("Win32Shutdown",ss);
Console.WriteLine(mo.ToString());
}
using System.Management;
...
// The calling process must have SeShutdownPrivilege for this to work.
SelectQuery query = new SelectQuery("select name from Win32_OperatingSystem where primary=true");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach(ManagementObject os in searcher.Get())
{
// Enable SeShutdownPrivilege
os.Scope.Options.EnablePrivileges = true;
ManagementBaseObject outParams = os.InvokeMethod("Reboot", null, null);
}
...
Willy.
"Diego" <die...@amdocs.com> wrote in message news:710601c1ee91$92f20e10$a5e62ecf@tkmsftngxa07...
An unhandled exception of
type 'System.Management.ManagementException' occurred in
system.management.dll
Additional information: Privilege not held.
>-----Original Message-----
>For a local system reboot try this:
>
>using System.Management;
>
>....
> // The calling process must have
SeShutdownPrivilege for this to work.
> SelectQuery query = new SelectQuery("select name
from Win32_OperatingSystem where primary=true");
> ManagementObjectSearcher searcher = new
ManagementObjectSearcher(query);
> foreach(ManagementObject os in searcher.Get())
> {
> // Enable SeShutdownPrivilege
> os.Scope.Options.EnablePrivileges = true;
> ManagementBaseObject outParams = os.InvokeMethod
("Reboot", null, null);
> }
>....
>
>Willy.
>
>"Diego" <die...@amdocs.com> wrote in message
news:710601c1ee91$92f20e10$a5e62ecf@tkmsftngxa07...
>> Anyone can send me a code example to reboot a PC.
>>
>> Thanks..
>
>
>.
>
I'm running my application under Local System Account
Thanks...
>.
>
Willy.
"Diego" <die...@amdocs.com> wrote in message news:790101c1eebf$1461ea10$b1e62ecf@tkmsftngxa04...
Start | Shutdown | Restart.
Couldn't resist :P