Restarting windows from c++

C

CRE

Or more exactly, how does one access the windows API to do things like
shutdowns
?

--chris
 
J

John Harrison

Or more exactly, how does one access the windows API to do things like
shutdowns
?

Your question is about the Windows API, not about C++. Ask in a Windows
programming group, for instance.
You are off topic here.

john
 
J

JKop

CRE posted:
Or more exactly, how does one access the windows API to do things like
shutdowns
?

--chris

#include <windows.h>

int main()
{
ExitWindowsEx(....
}


That's fun. But what's even more fun is getting into the device drivers for
the actual power, ie. electricity, to the computer, and just instantly
turning the computer off.

This if OFF-TOPIC, away with you to msnews.microsoft.com!


-JKOp
 
U

Unforgiven

Rainer Hausbach said:
int main()

IMHO W95/W98/ME only.
Win NT,W2k&XP need adjusted Rights.

Actually, this never works, at least not to shut down the system.

As you indicated, WinNT/2k/XP/2k3 need adjusted rights. You can however use
the code above to log off the current user without additional effort.
And while calling ExitWindowsEx to shut down is ok in Win9x, you can't
actually use it from a Console Application! ^_^
 
J

JKop

Unforgiven posted:
Actually, this never works, at least not to shut down the system.


Lies. Shutting down the system was all I ever did when I started out with
Win32 programming.

As you indicated, WinNT/2k/XP/2k3 need adjusted rights. You can however
use the code above to log off the current user without additional
effort. And while calling ExitWindowsEx to shut down is ok in Win9x,
you can't actually use it from a Console Application! ^_^

Lies. Win32 Console Applications have full access to dynamically linked
libraries, namely the Win32 API.


-JKop
 
U

Unforgiven

JKop said:
Unforgiven posted:



Lies. Shutting down the system was all I ever did when I started out with
Win32 programming.



Lies. Win32 Console Applications have full access to dynamically linked
libraries, namely the Win32 API.

Then the Platform SDK is lying. From the documentation for ExitWindowsEx():
"To shut down or restart the system, the calling process must use the
AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For
more information, see Running with Special Privileges.
Windows Me/98/95: ExitWindowsEx does not work from a console application."
http://msdn.microsoft.com/library/en-us/sysinfo/base/exitwindowsex.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top