Results 1 to 6 of 6

Thread: check if a service is runing

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    69

    check if a service is runing

    Hi all
    I use pcanywhere to remote pooling for a few stores,
    the problem is when pcanywhere is not waiting for a connection,
    pcanywhere wait host is a service and it runs a exe,
    the service executable path is C:\Program Files\Symantec\pcAnywhere\awhost32.exe
    I cant just shell it because maybe its running,
    is there a way in vb.net to check if the service is running if not start it?

    Thank You

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Funny...

    Wouldn't PCAnywhere check to see if an instance of itself was already running?

  3. #3
    Addicted Member
    Join Date
    Aug 1999
    Posts
    164
    This is cut from my project. Let me know if you need anything else.


    PHP Code:
    Private myService As ServiceController ' Used as a reference to the service
    ...

        Private Sub CheckServiceInstallation()
            ' 
    Verify to see if the service is installed.
            
    Dim installedServices() As ServiceController
            Dim tmpService 
    As ServiceController
            Dim i 
    As Integer 0

            installedServices 
    ServiceController.GetServices()

            For 
    Each tmpService In installedServices
                
    If tmpService.DisplayName "YOUR SERVICE NAME" Then
                    isServiceInstalled 
    True
                    
    ' Assign the service to myService, so we can use it later.
                    myService = tmpService
                    Exit For
                End If
            Next tmpService

          msgbox("Service Status: " + myService.Status.ToString())

    End Sub 
    Last edited by Shurijo; May 27th, 2003 at 05:02 PM.
    -Shurijo

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    69
    Hi Shurijo

    Thanks for your code
    i have one problem,
    Private myService As ServiceController
    ServiceController is not declared?
    Thanks for your help

  5. #5
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbtskCreatingServiceControllerComponentInstances.htm
    VB Code:
    1. [b]
    2. Imports System
    3. Imports System.ServiceProcess
    4. Imports System.Diagnostics
    5. [/b]
    6. Module Module1
    7.    Sub Main()
    8.       Dim myController As New ServiceController("IISAdmin")
    9.       If myController.CanStop Then
    10.          Debug.WriteLine(myController.ServiceName & " can be stopped.")
    11.       Else
    12.          Debug.WriteLine(myController.ServiceName & " cannot stop.")
    13.       End If
    14.    End Sub  
    15. End Module

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    69
    Thank you

    i have one problem,
    System.ServiceProcess
    vs.net namesoace or type can't be found?
    thanks again
    Last edited by cgj; May 28th, 2003 at 08:52 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width