Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SystemShutdown From Within a Service

Status
Not open for further replies.

mccartmd

Programmer
Feb 3, 2003
63
0
0
US
I am trying to shut down a Windows 2000 machine from within a service without success. The system will shut down fine if ran as a standalone process, but if it is run through a running service, it will only get as far as the "Shutting down Windows" screen. Does anyone have any advice as to how I can shut down the system?

Thanks in advance for any suggestions.

Mike
St. Louis
 
Services on NT boxes run under different privileges than normal applications. There is an option when you create a service for it to a "interact with desktop", you need to make sure that this is set.

By default it is running under a standard local system account.

If the above still doesnt work you can try running the service as administrator by supplying the admin name and password.

I dont know if this applies to windows 2000 but under XP there is a program called shutdown which you can call from the command line. this program takes arguments like, force, time out, message etc. So you can force a computer to shutdown. but again you need to be logged in as the administrator.

Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
To be more specific, I was asking about shutdown though code:

We have a service that we coded, and when the service receives a message to shutdown, it will only get as far as "Shutting Down Windows..." and hangs. We have determined that it hangs there because the shutdown code runs from within the service. If we run the code as a stand alone application, the computer shuts down fine. My question is if there is some specific coding we must do to make the computer shutdown completely. Thanks for suggestions.

Mike
 
Try to call CreateService() with SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS by creating the service.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top