Link to home
Start Free TrialLog in
Avatar of Leithauser
Leithauser

asked on

Shutting down Win2000 under program control

  In Windows 95/98, you can shut down or reboot Windows using the ExitWindowsEx User32 API call, ExitWindowsEx(2&, 0&) to reboot and ExitWindowsEx(1&, 0&) to shut down. This does not seem to work with Win2000. Does anyone know how to shut down and reboot Windows from within a program?
Avatar of jhance
jhance

InitiateSystemShutdown() is the preferred method.  See:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/shutdown_04ry.asp

BTW, ExitWindowsEx will work on W2K also but you probably lack the privilege SE_SHUTDOWN_NAME in your process token.  You need it regardless of whether you use InitiateSystemShutdown() or ExitWindowsEx() and you usually get it via the AdjustTokenPrivileges() API call.
Use the shutdown.exe tool is in the Resource Kit.
to use:

shutdown \\pc_name /c /t:1

to have it rebooted:

shutdown \\pc_name /c /r /t:1
Avatar of Leithauser

ASKER

None of these comments was able to answer my question, either because they were not sufficiently detailed or because the proposed solution involved external files. I found the solution I was looking for at this location
http://www.freevbcode.com/code/reboot.zip
This contained downloadable code that solved the problem. I therefore wish to withdraw or close down this question.
None of these comments was able to answer my question, either because they were not sufficiently detailed or because the proposed solution involved external files. I found the solution I was looking for at this location
http://www.freevbcode.com/code/reboot.zip
This contained downloadable code that solved the problem. I therefore wish to withdraw or close down this question.
None of these comments was able to answer my question, either because they were not sufficiently detailed
or because the proposed solution involved external files. I found the solution I was looking for at
this location
http://www.freevbcode.com/code/reboot.zip
This contained downloadable code that solved the problem. I am therefore deleting this question.
Please explain.  The URL I posted is complete and the Microsoft recommended method.

I posted that comment 2 weeks ago and you've ignored it until now.
The pages you pointed to were simply not clear enough for me. They were a bit cryptic or did not define their terms clearly enough for me to use them. This may be partly my fault for not being familiar enough with their terminology, but the code I found and referred to in my answer was clear and could be cut and pasted directly into my program. It was therefore the correct answer, or at least the best answer. If you had pointed me to that code, I would have awarded you the answer.
I just don't see how it could have been any clearer.  The URL I posted has a complete description of the system call as well as a link to another page with FULL SOURCE CODE of an example.

<<I just don't see how it could have been any clearer.>>

   It could have been clearer by being the answer I accepted. That is, somebody obviously hada clearer answer since I found one.
There is no accepted answer here.  You were attempting to DELETE this question.

Take it up with the moderator...
 I did not say that the accepted answer was here, just that there was an answer that was clearer than yours and I found acceptable elsewhere. This answer was posted by someone in reply to someone who had asked essentially the same question as me right here on Expert Exchange. (When I got no satisfactory answer here, I did a much more thorough search than before of Expert Exchange.) This was in reply to your statement "I just don't see how it could have been any clearer." to show you that it could have been clearer.
   BTW, here is a link to a question that I just had answered and I accepted the answer, just to show that I do accept answers that do clearly answer my question.

https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20291474
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Leithauser, please read below, these are the Grading guidelines you agreed to when signing up with EE.  Low grades are very uncommon, and weh you ask questions, the Experts will look at your grading profile, and if they see lower than A or atleast aberage, they wi probaly choose not to even participate next time.  If a comment leads you to a an answer, the Expert has done his/her job.
**********************************************************

How Do I Know What Grade to Give?
Although we use an A-D scale here at Experts Exchange, it works differently than, say, school grades. If one or more Experts' proposals are accepted as answers, they should usually be given an A or B grade, since they have taken the time to provide you with a working solution. If a possible solution is incomplete - ask for clarification or details before accepting the answer and grading it. People should not be given lower grades because of incorrect grammar or because you just accepted their answer or comment to close the question. Keep in mind, your question and any follow-up comments should be focused so that there can be a specific answer. The following is a good guideline to follow when grading:

A: The Expert(s) either provided you with a thorough answer or they provided you with a link to information that thoroughly answered your question. An "A" can also be given to any answer that you found informative or enlightening beyond the direct question that you asked.

B: The Expert(s) provided an acceptable solution, or a link to an acceptable solution, that you were able to use, although you may have needed a bit more information to complete the task.

C: Because Experts' reliability are often judged by their grading records, many Experts would like the opportunity to clarify if you have questions about their solutions. If you have given the Expert(s) ample time to respond to your clarification posts and you have responded to each of their posts providing requested information; or if the answers, after clarification, lack finality or do not completely address the issue presented, then a "C" grade is an option. You also have the option here of just asking Community Support to delete the question.

Remember, the Expert helping you today is probably going to be helping you next time you post a question. Give them a fair chance to earn an 'Excellent!' grade and they'll provide you with some amazing support.

This is why the grades here.

Regards,
ComTech
CS @ EE
To ComTech:

   Thank you for the information on the grading system. However, I do not understand why it is posted here. I have not given a grade here.
   In the last week, I have accepted two answers on other questions. One I gave an unqualified A to. The other I did give a C to, and it fit the "not completely address the issue presented" description. It pointed me to a general subject that gave me an idea of where to look elsewhere for a partial answer, which told me what I had to do but not how to do it. Further inquiries lead to not result. I eventually found that out through my own research. I awarded the person the points for getting me started on the right path, but did not feel that I could honestly say the person had provided the answer.