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 exists
- vb net check if service is running
- how to know whether the windows service is started or not in c#
- how to test a windows service vb net
- if exist windows service vb net
- test for service exists in vb dot net
- vb net check if a service is running
- check if print spooler service is running vb
- vb net check service running
- vb net console application for checking windows service status
