Click to See Complete Forum and Search --> : How could I shutdown a computer in my VC++ program?


Noodle
April 15th, 1999, 10:57 AM
I want my program could shutdown computer, I know how to suspend it, but How can I shutdown it?
Thanks.

April 15th, 1999, 11:04 AM
ExitWindowsEx ( EXW_SHUTDOWN, 0 );

will start a shutdown but will prompt the user whether to close any active applications - this gives the user the chance to cancel the shutdown.

ExitWindowsEx ( EXW_SHUTDOWN|EXW_FORCE, 0 );

does a shutdown, killing any active applications.

ValerieB
April 15th, 1999, 11:56 AM
There is an additional snag if you're running on Windows NT. You have to set up the application's process token with permissions to allow you to shut down the PC.

The functions you'll need to look at are:
OpenProcessToken()
GetTokenInformation()
LookupPrivilegeValue()
AdjustTokenPrivileges()

If you're running on Windows 95/98, you don't have to worry about this.

Good luck!

Valerie Bradley
http://www.synthcom.com/~val
val@synthcom.com