How to shutdown your computer using C++?

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2009
Posts: 326
Reputation: NicAx64 will become famous soon enough NicAx64 will become famous soon enough 
Solved Threads: 19
NicAx64's Avatar
NicAx64 NicAx64 is offline Offline
Posting Whiz

Re: How to shutdown your computer using C++?

 
0
  #21
Mar 20th, 2009
There are some registry values in the windows that stops shutdown
check this out also. Windows is a flat system that harder to debug.

Btw that command wont work on vista i dont think
MSDN says if you have a windows version 2000 above , this will works.Read the MSDN. Anyway if you refering about that "shutdown" shell command then if it's not working in the windows shell then it will surely not working inside your program too.

That may be a registry error.

This may be a user priviledge problem ,


But there should be a reason , so we are going to debug it.
Oky what is the error code ? Then just open the Error Lookup tool
in VS and submit that value and check it.

There is a error but there should be a something reason. Hopefully
there can be slove exists for that problem. ( anyway not every problem have an answer).
Nothing like a kernel pannic !
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 326
Reputation: NicAx64 will become famous soon enough NicAx64 will become famous soon enough 
Solved Threads: 19
NicAx64's Avatar
NicAx64 NicAx64 is offline Offline
Posting Whiz

Re: How to shutdown your computer using C++?

 
0
  #22
Mar 20th, 2009
Originally Posted by mitrmkar View Post
Nothing in the MSDN documentation on ExitWindowsEx() indicates that. How did you came into that conclusion?
Agreed !
That way of thinking is bad for your debugging skills.
Nothing like a kernel pannic !
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 326
Reputation: NicAx64 will become famous soon enough NicAx64 will become famous soon enough 
Solved Threads: 19
NicAx64's Avatar
NicAx64 NicAx64 is offline Offline
Posting Whiz

Re: How to shutdown your computer using C++?

 
0
  #23
Mar 20th, 2009
if( ! ExitWindowsEx(...))
{
   
    // maybe lastError will tell something useful ...
    DWORD lastError = GetLastError();
}
    // Toggle a debug flag on this line //

and rebuild and press GO , then the debugger will stop in this
line. Then you can see what's going on.
Last edited by NicAx64; Mar 20th, 2009 at 12:18 pm.
Nothing like a kernel pannic !
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: How to shutdown your computer using C++?

 
0
  #24
Mar 20th, 2009
Originally Posted by OmniX View Post
Posted what just happened but then shouldnt I not be able to run shutdown.exe if i didnt have the required access?

I really think this is a vista problem? Anyone else using vista?
It is not a Vista problem. Vista uses same APIs to shutdown the system.
You certainly have required permissions and privileges if you can shutdown the system by Shutdown.exe

You just need to be more careful that you need to *enable* shutdown privilege before you call ExitWindowEx API. By default, this privilege is disabled for all users. The code on MSDN enable this privilege and calls the API.

2 prerequisites
a) You must have the shutdown privilege (It is not 'permission' it is called 'privilege')
b) You must have this privilege enabled.

Many times this privilege is present but not enabled. You would need additional programming effort to enable it.

Also, you can try turning off the UAC and running your application to see if that makes any difference to you.

Off the records::
If that doesnot work, open a support incident with Microsoft I will have a dedicated engineer work with you. If it is idenified as a Vista problem Microsoft will not charge you!
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,273
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 543
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: How to shutdown your computer using C++?

 
-7
  #25
Mar 20th, 2009
I know that to shutdown the system using the NET Framework, you must change your application so that it asks for an elevation of privileges on execution, or else it wont work on vista.

So i assume you must do the same in this case
Last edited by jbennet; Mar 20th, 2009 at 1:16 pm.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 87
Reputation: prushik is on a distinguished road 
Solved Threads: 4
prushik prushik is offline Offline
Junior Poster in Training

Re: How to shutdown your computer using C++?

 
1
  #26
Mar 20th, 2009
try using system("shutdown -s -f -t 00");
Its not the best solution, but whether it works or not, it will be informative.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,662
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to shutdown your computer using C++?

 
0
  #27
Mar 21st, 2009
Originally Posted by prushik View Post
try using system("shutdown -s -f -t 00");
Its not the best solution, but whether it works or not, it will be informative.
Yes -- I just tested it on my Vista Home and it works perfectly.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 87
Reputation: prushik is on a distinguished road 
Solved Threads: 4
prushik prushik is offline Offline
Junior Poster in Training

Re: How to shutdown your computer using C++?

 
0
  #28
Mar 21st, 2009
I have seen it not work on some machines. In high school i tried it on the school PCs and it wouldn't work (I messed with my friends in that class all the time). So if OminiX can't get that to work his user account may not have the necessary permissions.
If it does work for OminiX then the other suggestions may not have worked because of something in the registry blocking shutdowns. If that is the issue, another (better) solution could be implemented.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,662
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to shutdown your computer using C++?

 
0
  #29
Mar 21st, 2009
I think the user will have to be logged in under an Administrative account for that to work. In school users probably don't have those permissions, and there is nothing you can do about it short of getting the instructor to let you log in as Administrator (and that's highly unlikely)
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 87
Reputation: prushik is on a distinguished road 
Solved Threads: 4
prushik prushik is offline Offline
Junior Poster in Training

Re: How to shutdown your computer using C++?

 
0
  #30
Mar 21st, 2009
Yes that's true. That's pretty much what I was trying to say. If it doesn't work its most likely because you need admin privileges.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 3785 | Replies: 38
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC