Check if Service is running?

  • Thread starter Thread starter Joris De Groote
  • Start date Start date
J

Joris De Groote

Hi,

can vb check if a windows service is running or not? ( Webclient )

Thanks
Joris
 
Joris De Groote said:
can vb check if a windows service is running or not? ( Webclient )

On the client or on the server? I doubt that this is possible on the client
without writing some ugly ActiveX control or .NET Browser Control. Maybe
it's better to develop a classic rich-client Windows Forms application
instead of a Web application.
 
Joris,

If you set a reference to System.ServiceProcess, you could use a
function like this one below to check it. I use it in a service of
mine to check for dependency services.

Function CheckIfServiceIsRunning(ByVal serviceName As String) As
Boolean

Dim mySC As ServiceProcess.ServiceController
mySC = New ServiceProcess.ServiceController(serviceName)
If mySC.Status = ServiceProcess.ServiceControllerStatus.Stopped
Then
' Service isn't running
Return False
ElseIf mySC.Status =
ServiceProcess.ServiceControllerStatus.Running Then
' Service already running
Return True
End If

End Function
 
You'd also want to put that in a Try Catch block. You'll get an
exception if the service name is invalid IIRC.
 
So you are checking the server to verify this particular service is running
right?



--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com



Joris De Groote said:
It's a VB.NET program that runs on a server, so it's not a web
application.
 
Back
Top