Here is the awesome VB.Net code to check whether the windows service is running or not by passing the service name:
Instructions:
- Open a New Console application
- Add a new bas module called modMain
- Set a reference to System.ServiceProcess (Go to Project > Add Reference and select System.ServiceProcess under .Net tab and click OK.)
- Copy the following code to modMain bas module
Module modMain
Sub Main()
If IsServiceRunning("Print Spooler") Then
Console.WriteLine("Print Spooler Service Running in this machine." & vbCrLf)
Else
Console.WriteLine("Print Spooler Service not running in this machine; or the service doesn't exists.\n" & vbCrLf)
End If
Console.WriteLine("Hit Enter to exit.")
Console.Read()
End Sub
Function IsServiceRunning(ByVal sServiceName As String) As Boolean
Try
Dim myServiceController As ServiceProcess.ServiceController
myServiceController = New ServiceProcess.ServiceController(sServiceName)
Return myServiceController.Status = ServiceProcess.ServiceControllerStatus.Running
Catch ex As Exception
Console.WriteLine(ex.ToString)
Return False
End Try
End Function
End ModuleProject Type: Console
Language: VB.Net
Tested with: VS 2008
Incoming search terms:
- vb net check if service is running
- how to check window service is running
- vb net check if a service is running
- visual basic Check if a service is running
- vb net check if service exists
- VB code to check windows service
- test for service exists in vb dot net
- net code to check if windows service is running
- how to test a windows service vb net
- how to determine if a servics is running in vb net