943,722 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 14202
  • C++ RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Mar 20th, 2009
0

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

There are some registry values in the windows that stops shutdown
check this out also. Windows is a flat system that harder to debug.

Quote ...
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).
Reputation Points: 86
Solved Threads: 43
Posting Pro
NicAx64 is offline Offline
532 posts
since Mar 2009
Mar 20th, 2009
0

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

Click to Expand / Collapse  Quote originally posted by mitrmkar ...
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.
Reputation Points: 86
Solved Threads: 43
Posting Pro
NicAx64 is offline Offline
532 posts
since Mar 2009
Mar 20th, 2009
0

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

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.
Reputation Points: 86
Solved Threads: 43
Posting Pro
NicAx64 is offline Offline
532 posts
since Mar 2009
Mar 20th, 2009
0

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

Click to Expand / Collapse  Quote originally posted by OmniX ...
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!
Reputation Points: 39
Solved Threads: 24
Junior Poster
dubeyprateek is offline Offline
176 posts
since Mar 2006
Mar 20th, 2009
-7

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

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.
Moderator
Featured Poster
Reputation Points: 1764
Solved Threads: 574
Moderator
jbennet is offline Offline
16,505 posts
since Apr 2005
Mar 20th, 2009
1

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

try using system("shutdown -s -f -t 00");
Its not the best solution, but whether it works or not, it will be informative.
Reputation Points: 61
Solved Threads: 5
Junior Poster
prushik is offline Offline
101 posts
since Oct 2007
Mar 21st, 2009
0

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

Click to Expand / Collapse  Quote originally posted by prushik ...
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.
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 21st, 2009
0

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

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.
Reputation Points: 61
Solved Threads: 5
Junior Poster
prushik is offline Offline
101 posts
since Oct 2007
Mar 21st, 2009
0

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

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)
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 21st, 2009
0

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

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.
Reputation Points: 61
Solved Threads: 5
Junior Poster
prushik is offline Offline
101 posts
since Oct 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