DOn't know if this the correct way or not but it's what one of our programs
is doing to see if a Service is installed.
'
' Check to see if VNC is installed
'
Dim scServices() = ServiceControll er.GetServices( )
Dim i As Integer = 0
While i < scServices.Leng th
'MessageBox.Sho w(scServices(i) .DisplayName)
If scServices(i).D isplayName = "VNC Server" Then
m_bVNC = True
End If
i = i + 1
End While
If m_bVNC Then
'
' Check to see if VNC is already running, If so indecate
that VNC is running
'
Try
If m_VNC Is Nothing Then
m_VNC = New ServiceControll er("VNC Server")
End If
m_VNC.Refresh()
If m_VNC.Status <> ServiceControll erStatus.Stoppe d Then
tbVnc.ImageInde x = 7
tbVnc.Text = "VNC - ON"
End If
Catch exp As Exception
MsgBox(m_VNC.Se rviceName & " is in state:" &
m_VNC.Status.To String() & vbNewLine & _
"Could not start service")
Finally
m_VNC.Dispose()
m_VNC = Nothing
End Try
Else
tbVnc.Enabled = False
End If
"Lucas Tam" wrote:
Hi all,
If I create a serviceControll er like:
srvController = New ServiceControll er("Fubar")
serviceControll er will be created regardless if the service exists or not.
It will only throw an exception if I access the properties of the
serviceControll er.
Is there a way to check that the service actually exists before creating
it?
Thanks.
--
Lucas Tam (RE********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/