Stopping service from within OnStart sub

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In the OnStart sub of my service (as the service is starting up) I check for
certain things. If one of a few things don't jive, I want to "cancel" the
starting of the service.

How do I accomplish this? Currently I am using the Stop method of the
ServiceController but that does not seem to be working.

Is it possible to "stop the start" of a service half way through its Start?
Are there other options?

Scott
 
SQLScott said:
In the OnStart sub of my service (as the service is starting up) I check
for
certain things. If one of a few things don't jive, I want to "cancel" the
starting of the service.

How do I accomplish this? Currently I am using the Stop method of the
ServiceController but that does not seem to be working.

Is it possible to "stop the start" of a service half way through its
Start?
Are there other options?

Sure. Just write an event log entry describing the failure and throw an
exception.

David
 
Scott,
Its (can be) even easier then David suggests.

Just throw an exception!

ServiceBase itself will write an entry to the event log for you if you have
ServiceBase.AutoLog property set to true. AutoLog=True is the default
setting...

Hope this helps
Jay
 
Back
Top