|
-
Aug 5th, 2004, 04:34 PM
#1
Thread Starter
Frenzied Member
Stop my service through it's own code?
How does one stop a service through the code itself? I want to check for a valid license, and if it's expired, shut down the service.
Calling this method in OnStart:
VB Code:
Private Sub CheckLicense()
EventLog1.WriteEntry("Your license has expired. Please contact support to obtain a new license.", EventLogEntryType.Error)
Logger.Log("I", Encoding.ASCII.GetBytes("Your license has expired. Please contact support to obtain a new license."))
'Application.Exit()
'OnStop()
Me.Dispose(True)
End Sub
Application.Exit, OnStop and Me.Dispose do not shut it down.
Thanks,
Mike
-
Aug 6th, 2004, 09:48 AM
#2
Thread Starter
Frenzied Member
FWIW, I've googled for hours and apparently, in this version, you just can't do this. That statement was from someone at Microsoft. The workaround suggested was to spawn another process which uses the ServiceController class to stop your service. I tried this within my service itself, and it does not work.
-
Aug 6th, 2004, 11:22 AM
#3
You could force the OnStart() sub to timeout by putting a massive sleep statement in there - the services control will report something like "[servicename] failed to start up - please see the eventlog for details".
-
Aug 6th, 2004, 11:35 AM
#4
Thread Starter
Frenzied Member
Thanks Merrion, that does the trick. Nice and simple, too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|