PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How can a service self-terminate?-VBForums
Results 1 to 3 of 3

Thread: How can a service self-terminate?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    7

    How can a service self-terminate?

    I'm writing a service, and I want it to be able to stop itself upon startup if it needs to. I've tried Application.Exit, but that doesn't work.

    Please advise. Thanks!

  2. #2
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141

    Re: How can a service self-terminate?

    You have to tell the Service controller to stop the service. You can actually stop any service with this code.
    VB Code:
    1. Dim mServiceController As System.ServiceProcess.ServiceController
    2. mServiceController = New System.ServiceProcess.ServiceController("IISAdmin") 'Change this to your Services name (this will stop IIS)
    3. If mServiceController.Status = ServiceProcess.ServiceControllerStatus.Running Then
    4.       If mServiceController.CanStop = True Then
    5.               mServiceController.Stop()
    6.       End If
    7. End If
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    7

    Re: How can a service self-terminate?

    Thanks!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width