943,767 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 14206
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 19th, 2009
0

How to shutdown your computer using C++?

Expand Post »
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
Similar Threads
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Mar 19th, 2009
0

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

Try system().
Reputation Points: 163
Solved Threads: 91
Posting Pro in Training
nucleon is offline Offline
476 posts
since Oct 2008
Mar 19th, 2009
0

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

Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Mar 19th, 2009
0

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

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
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Mar 20th, 2009
0

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

Something like this

C++ Syntax (Toggle Plain Text)
  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++
Reputation Points: 30
Solved Threads: 3
Junior Poster
power_computer is offline Offline
144 posts
since Feb 2009
Mar 20th, 2009
0

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

It is "shutdown" no space but even then didnt work, are you 100% sure it worked with yours?
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Mar 20th, 2009
0

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

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.
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008
Mar 20th, 2009
0

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

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:
cpp Syntax (Toggle Plain Text)
  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.
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Mar 20th, 2009
0

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

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Mar 20th, 2009
0

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

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?

cpp Syntax (Toggle Plain Text)
  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.
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Improvements to Quicksort using the Median of 3 partition and Insertion sort
Next Thread in C++ Forum Timeline: no matching function call to for_each





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC