Solved

Reboot from MFC application

Posted on 2007-04-02
8
1,467 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:pbsmbc
  • 3
  • 3
  • 2
8 Comments
 
LVL 9

Expert Comment

by:Priyesh
Comment Utility
void CMyView::OnBnClicked()
{
   //save all your work
  ExitWindowsEx(EWX_REBOOT, 0) ;
}
0
 

Author Comment

by:pbsmbc
Comment Utility
Does the user (who is using the application) need to have administrative privilage to reboot?
0
 
LVL 9

Expert Comment

by:Priyesh
Comment Utility
Yes, please take a look at this link from MSDN for some sample code.

http://msdn2.microsoft.com/en-us/library/aa376871.aspx
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
>>Does the user (who is using the application) need to have administrative
>>privilage to reboot?

No. Just the SE_SHUTDOWN_NAME when using

InitiateSystemShutdown(NULL,NULL,0,TRUE,TRUE);

See also http://msdn2.microsoft.com/en-us/library/aa376883.aspx ("System Shutdown Functions") and http://msdn2.microsoft.com/en-us/library/aa376881.aspx ("Shutting Down")
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 9

Expert Comment

by:Priyesh
Comment Utility
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.
0
 

Author Comment

by:pbsmbc
Comment Utility
Thanks jkr.
What is the difference between InitiateSystemShutdown and exitwindowex?
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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.
0
 

Author Comment

by:pbsmbc
Comment Utility
Our application is running on both XP and NT.  
So is InitiateSystemShutdown better choice?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 109
Expand to include initial dialog with two choices. 9 59
iSeries DB2 Query 2 83
changeXy challenge 13 56
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now