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() = ServiceController.GetServices()
Dim i As Integer = 0
While i < scServices.Length
'MessageBox.Show(scServices(i).DisplayName)
If scServices(i).DisplayName = "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 ServiceController("VNC Server")
End If
m_VNC.Refresh()
If m_VNC.Status <> ServiceControllerStatus.Stopped Then
tbVnc.ImageIndex = 7
tbVnc.Text = "VNC - ON"
End If
Catch exp As Exception
MsgBox(m_VNC.ServiceName & " is in state:" &
m_VNC.Status.ToString() & 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 serviceController like:
srvController = New ServiceController("Fubar")
serviceController will be created regardless if the service exists or not.
It will only throw an exception if I access the properties of the
serviceController.
Is there a way to check that the service actually exists before creating
it?
Thanks.
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/