?
Solved

Reboot from MFC application

Posted on 2007-04-02
8
Medium Priority
?
1,530 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 9

Expert Comment

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

Author Comment

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

Expert Comment

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

http://msdn2.microsoft.com/en-us/library/aa376871.aspx
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
jkr earned 1500 total points
ID: 18843885
>>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
 
LVL 9

Expert Comment

by:Priyesh
ID: 18845610
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
ID: 18847130
Thanks jkr.
What is the difference between InitiateSystemShutdown and exitwindowex?
0
 
LVL 86

Expert Comment

by:jkr
ID: 18848508
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
ID: 18878898
Our application is running on both XP and NT.  
So is InitiateSystemShutdown better choice?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

771 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