Solved

Shutting down Win2000 under program control

Posted on 2002-04-02
15
159 Views
Last Modified: 2010-04-13
  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?
0
Comment
Question by:Leithauser
15 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6914415
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.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6914425
0
 

Expert Comment

by:oricks
ID: 6918670
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
0
 
LVL 5

Author Comment

by:Leithauser
ID: 6953836
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.
0
 
LVL 5

Author Comment

by:Leithauser
ID: 6953837
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.
0
 
LVL 5

Author Comment

by:Leithauser
ID: 6953862
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.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6954384
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.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 5

Author Comment

by:Leithauser
ID: 6954910
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.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6954933
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.

0
 
LVL 5

Author Comment

by:Leithauser
ID: 6954961
<<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.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6954992
There is no accepted answer here.  You were attempting to DELETE this question.

Take it up with the moderator...
0
 
LVL 5

Author Comment

by:Leithauser
ID: 6955095
 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.

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20291474
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 6955568
Ok, here it is again.

Comment from me accepted as answer.  jhance, look for your question in this topic area.

Leithauser,
As stated in the previous question by you, the answer has been posted by jhance, but not to your satisfaction.  The same in this question.  The bottom line is, it is the correct answer.

Computer101
E-E Moderator
0
 

Expert Comment

by:ComTech
ID: 6955938
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
0
 
LVL 5

Author Comment

by:Leithauser
ID: 6956139
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.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now