Home > Windows Service > Windows Service Exit Codes

Windows Service Exit Codes

Contents

Either that, or I would call Stop on myself (and set the ExitCode as well, if you wanted). Is there a "cancel event" of some sort I can use in the OnStart event? This is the code that registers the service(s) included in this application with the host operating system. About Me Mike Christian Mike is a computer programmer in Salt Lake City, Utah (USA) who enjoys being with his family, having fun, having fun while programming, and building stuff. Source

When using ServiceBase.Stop the messages in the eventlog are even mor confusing. What am I missing? Best regards, Per Reply ↓ Ravi Khambhati February 17, 2010 at 3:51 am I tried to this but did not get sucess. Wrapping the exception, and passing the asynchronous exception as the InnerException, preserves the call stack of the asynchronous exception. recommended you read

Windows Service Exit Codes

If we start the service via services.msc, we get the following pop-up immediately: And the service, as we would expect, did not start successfully. One of the problems with this implementation is that you end up throwing an unhandled exception, by design, from the Stop event handler. If code directly returns when connection testing fails, the service still started successfully, and I need to check log file to know the db is dead. Should I use SetServiceStatus() to set service to share|improve this answer answered Apr 21 '10 at 7:40 Mikael Svenson 25.6k44762 1 thanks, sorry but i didn't get it.

  1. OnStart must not block, otherwise it appears to the SCM that the service has not started correctly.
  2. Re-throwing my exception & cutting out my manual "stopping" code works.
  3. I want them to fail if errors are thrown during startup (in OnStart() method).
  4. Try our newsletter Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).
  5. This will populate an empty service.

voidSetServiceStatus(boolstartService) I created this method, to easily start and stop services. Similar topics About window service Default path for Windows Service How is the start sequence for windows service Service unable to start Another Windows Service Question Problem with Windows Service Application Additionally a very confusing message is output in this case by the system. Success!

I have not seen it documented anyplace other then numerous newsgroup posts, by myself & others. C# Setservicestatus This demonstration uses Visual Studio 2010. Because of a missing line in my .config file it crashed with an IOException, before it started any worker thread. http://stackoverflow.com/questions/12068492/stop-windows-service-in-onstart-method share|improve this answer answered Nov 16 '10 at 17:52 Heinzi 98.2k28207326 1 +1 that PS was just what i was looking for.

Otherwise call Stop from a new thread. These settings are stored in an XML file with a .CONFIG extension, deployed along with the .EXE file. All applications programmers encounter situations where something needs continuous monitoring, housekeeping, or something needs to happen automatically, when certain conditions or situations arise. As a positive side-effect, it logs the failure of your service into the event log.

C# Setservicestatus

No, create an account now. his explanation Solutions? Windows Service Exit Codes Notice that one of the reasons that this function can fail is: ERROR_SERVICE_CANNOT_ACCEPT_CTRL The requested control code cannot be sent to the service because the state of the service is SERVICE_STOPPED, Servicebase Onstart I recommend setting it to 13816, since this results in the message, "An unknown error has occurred." See the windows error codes.

This exception is not caught. this contact form I still need to stop it manually. You can skip down to the installation configuration part, if you wish. Subscribed!

Email Address Search Articles Your First Steps A DevOps Checklist A Manifesto for Agile Software Branch for Release (and nothing else) DevOps Best Practices, Part 1 of 4 – Automate only Thursday, May 17, 2007 9:20 AM Reply | Quote Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. Where will the second Fantastic Beasts film be set? have a peek here You should also be able to go to the Windows Event Viewer and see events related to starting and stopping your service in the Application and System logs.

share|improve this answer edited Nov 16 '10 at 18:05 answered Nov 16 '10 at 17:53 Steve Townsend 42k453111 13 The answer I was looking for is contained in this answer. I have found that if OnStart() has no more than one line in it, then I dont get the "The service started and then stopped.Some services stop automatically if they have Now that we’ve done all the basics, you should be able to build your service and install it.

When set to true, these basically subscribehandlermethods in your service to the operating system service events.

In theSolution Explorerwindow, expand thePropertiesnode of the Windows Service project. If Initialize fails (i check log file) and I try to stop service from Administrative Tools->Services i get: Could not stop the SomeService on Local Computer. Why does typography ruin the user experience? It completely destroys the service, but the SCM also knows that it is shutdown.

Do you know how it can be addressed? –Eugene D. I'm developing a Windows Service application. Sign Up Now! http://discusswire.com/windows-service/windows-service-logging-best-practices.html However, if we look at the event viewer, we notice that there is a useful error message there: The framework has kindly gone ahead and logged the issue for us, even

So awesome. The System.Configuration.Install namespace contains objects that expose code to the setup project. Also see this related SO question, and dev newsgroup thread. The service uses a worker thread to do its work.

It doesn't affect the Windows Application log but does include a message in the System log. 2 - Calling Stop results in a "Service successfully stopped" message in the Application log. If you're having a computer problem, ask on our forum for advice. If you are unfamiliar with Setup projects, I recommend taking some time to learn about them. When I added a resistor to a set of christmas lights where I cut off bulbs, it gets hot.

SetServiceStatus(false); } //Startsandstopsthespecifiedservice. This is important; because, this information is visible to the end user. But it dosn't seems to working properly. more hot questions question feed lang-cs about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation

Some virtual machine environments, such as VM Ware, allow you to roll back changes without shutting down the virtual machine, by simply rebooting the virtual machine. voidSetServiceStatus(boolstartService) { ServiceControllerStatussetStatus= startService?ServiceControllerStatus.Running:ServiceControllerStatus.Stopped; try { controller=newServiceController("Service1"); if(controller!=null&&controller.Status!=setStatus) { if(startService) controller.Start(); else controller.Stop(); controller.WaitForStatus(setStatus,newTimeSpan(0,0,30)); } } catch{ //TODO } } } Let's examine parts of this code, to understand what is Hello and welcome to PC Review.