Solved

Reboot from MFC application

Posted on 2007-04-02
8
1,501 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 86

Accepted Solution

by:
jkr earned 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 45
deburging in oracle form 12 105
method notes when mouse over in eclipse 5 87
Capture logon name 13 87
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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