Link to home
Start Free TrialLog in
Avatar of pbsmbc
pbsmbc

asked on

Reboot from MFC application

Hi,

Is there any function in MFC that will reboot(soft)  the work station while exiting from a MFC application.

The requirement is if the user press a button it will exit the application and it will reboot the
computer also.  If it's possible is any source code available?

I am using VC++ 6.

Thanks
Avatar of Priyesh
Priyesh

void CMyView::OnBnClicked()
{
   //save all your work
  ExitWindowsEx(EWX_REBOOT, 0) ;
}
Avatar of pbsmbc

ASKER

Does the user (who is using the application) need to have administrative privilage to reboot?
Yes, please take a look at this link from MSDN for some sample code.

http://msdn2.microsoft.com/en-us/library/aa376871.aspx
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry for answering Yes to your "is administrative privileges required " question. jkr above is right and that's what the link i qouted with the comment indicates as well.
Avatar of pbsmbc

ASKER

Thanks jkr.
What is the difference between InitiateSystemShutdown and exitwindowex?
Both will have the same effect, yet 'InitiateSystemShutdown()' is the more NT-like solution that is safe to follow up the path over XP to it's successors.
Avatar of pbsmbc

ASKER

Our application is running on both XP and NT.  
So is InitiateSystemShutdown better choice?