Self-Terminating a Service

rlrcstr

New member
Joined
Dec 3, 2003
Messages
2
Ive got a service that runs just fine, but I want it to be able to terminate itself if the startup parameters are invalid. The service uses a timer to trigger its functionality. This is what Ive got so far...

In the OnStart event, I read and validate the startup params. If invalid, I set the validConfig flag to false. At the end of OnStart, I start the services timer.

In the Elapsed event for the timer, I check the validConfig flag. If False then I do this:

Dim sc As New ServiceController(Me.ServiceName)
sc.Stop

---

But I always get an exception that I couldnt attach to the service. (I even tried attaching to another service, just to see if it would work, but I get the same exception.)

What am I missing? How do you tell a service to stop itself? :confused: Thanks.

Jerry
 
The exception is:

Couldnt attach to service "filedepotagent" on machine "."

Thats the name of my service, but any service I try to attach to give the same exception.

I know its not too descriptive.
 
Back
Top