How to shutdown your computer using C++?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

How to shutdown your computer using C++?

 
0
  #1
Mar 19th, 2009
I know the dos command is "shutdown" then with your parameters of "-s -t xxx" etc.

Anyways so "How to shutdown your computer using C++?"

Thanks, Regards X
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

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

 
0
  #2
Mar 19th, 2009
Try system().
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,346
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: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

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

 
0
  #3
Mar 19th, 2009
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: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

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

 
0
  #4
Mar 19th, 2009
Im a newb to C++, what paramters need to be used with the functions and do they require an include file? possible small example?

Thanks, Regards X
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 141
Reputation: power_computer is an unknown quantity at this point 
Solved Threads: 2
power_computer power_computer is offline Offline
Junior Poster

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

 
0
  #5
Mar 20th, 2009
Something like this

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6.  
  7. system("shut down -s -t 10");
  8. return 0;
  9.  
  10. }

Shuts it down in ten seconds this is using dev c++
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

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

 
0
  #6
Mar 20th, 2009
It is "shutdown" no space but even then didnt work, are you 100% sure it worked with yours?
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

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

 
0
  #7
Mar 20th, 2009
Firstly, don't use sysrtem. use the function given to you by AncientDragon.

Secondly for an example, read the page it has a link to one.
Thirdly, that page tells you what parameters are needed, what they could be and what they do. Also it tells you what headers you need etc.

Please read information when someone points you to it, they don't do it for fun. They do it to try and help.

Chris
Last edited by Freaky_Chris; Mar 20th, 2009 at 5:50 am.
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

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

 
0
  #8
Mar 20th, 2009
Ok thankyou Chris for that abusive and useless post. (If I didnt need help I wouldnt have posted)

If someone can give me an example using ExitWindowsEx(), like power_computer tried to give me one using system("").

My attemps have included:
  1. ExitWindowsEx(EWX_POWEROFF, SHTDN_REASON_MAJOR_OTHER);
  2. // AND
  3. system("shutdown -s -t 180");

So any ideas?

Thanks, Regards X
Thanks
Last edited by OmniX; Mar 20th, 2009 at 9:11 am.
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,346
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: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

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

 
0
  #9
Mar 20th, 2009
Delete line 3 (system(...) because its not needed. Otherwise, your line #1 looks ok to me, as long as you are running as administrator account.
Last edited by Ancient Dragon; Mar 20th, 2009 at 9:31 am.
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: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

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

 
0
  #10
Mar 20th, 2009
Ya they were just my attemps nothing works, this is my whole code below.
I am assuming that my ExitWindowsEx line is fine? (Whoops my internet is lagging didnt see ur second line)
Am I missing include files? Variables? Etc? I have vista also.
So what looks to be the problem?

  1. // Include Files
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <stdio.h>
  5. #include <time.h>
  6. #include <windows.h>
  7. using namespace std;
  8.  
  9. int main () {
  10. // Shutdown
  11. cout << "Shutdown Complete!" << endl;
  12. ExitWindowsEx(EWX_POWEROFF, SHTDN_REASON_MAJOR_OTHER);
  13. //system("shutdown.exe -s -t 180");
  14.  
  15. // Return Carriage
  16. return 0;
  17. }

Thanks, Regards X
Last edited by OmniX; Mar 20th, 2009 at 9:45 am.
"You never stop learning." - OmniX
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
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC