Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reboot example

19 views
Skip to first unread message

Diego

unread,
Apr 28, 2002, 4:49:14 AM4/28/02
to
Anyone can send me a code example to reboot a PC.

Thanks..

Robert Jeppesen

unread,
Apr 28, 2002, 5:07:14 AM4/28/02
to
As posted by Rick Zhuang four days ago...


[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...

Eliyahu (Vyacheslav) Biktagirov

unread,
Apr 28, 2002, 5:20:07 AM4/28/02
to
Try this code. You should have SeShutdownPrivilege
privilege to run it in WinNT.


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());
}

Willy Denoyette [MVP]

unread,
Apr 28, 2002, 6:37:23 AM4/28/02
to
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...

Diego

unread,
Apr 28, 2002, 7:54:11 AM4/28/02
to
I get and exception when call the InvokeMethod...

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..
>
>

>.
>

Eliyahu (Vyacheslav) Biktagirov

unread,
Apr 28, 2002, 8:22:21 AM4/28/02
to
Your Windows user doesn't have this privilege. Please add
it.

Diego

unread,
Apr 28, 2002, 10:14:59 AM4/28/02
to
Can you give an example to do it?

I'm running my application under Local System Account

Thanks...

>.
>

Willy Denoyette [MVP]

unread,
Apr 28, 2002, 12:46:21 PM4/28/02
to
Hmm.. The localsystem account has this privilege, are you sure the program is not impersonating someone else?

Willy.

"Diego" <die...@amdocs.com> wrote in message news:790101c1eebf$1461ea10$b1e62ecf@tkmsftngxa04...

Paul Gentry

unread,
Apr 28, 2002, 5:13:04 PM4/28/02
to

"Diego" <die...@amdocs.com> wrote in message
news:710601c1ee91$92f20e10$a5e62ecf@tkmsftngxa07...

> Anyone can send me a code example to reboot a PC.
>
> Thanks..

Start | Shutdown | Restart.

Couldn't resist :P

0 new messages