To Check a Window Service on C#.Net
-
Hi, I want to create a start up application that will check the MYSQL SERVICE RUNNING or Not & IF it is running then it will Kill that & Exit. Else it will run an exe setup file. Any one Please suggest me how can i check WINDOW SERVICE in DotNet. & How can i kill APACHE by using command line from my programe. Thanks connect me @ panda.biswabhusan@gmail.com
-
Hi, I want to create a start up application that will check the MYSQL SERVICE RUNNING or Not & IF it is running then it will Kill that & Exit. Else it will run an exe setup file. Any one Please suggest me how can i check WINDOW SERVICE in DotNet. & How can i kill APACHE by using command line from my programe. Thanks connect me @ panda.biswabhusan@gmail.com
Hi, take a look on the class ServiceController (include Reference System.ServiceProcess). Sample: ServiceController controller = new ServiceController(); controller.Refresh(); // Controller should read state if (controller.State == ServiceControllerStatus.Running) // Service is running... ... you will receive an exception if the specified service does not exist.
-
Hi, I want to create a start up application that will check the MYSQL SERVICE RUNNING or Not & IF it is running then it will Kill that & Exit. Else it will run an exe setup file. Any one Please suggest me how can i check WINDOW SERVICE in DotNet. & How can i kill APACHE by using command line from my programe. Thanks connect me @ panda.biswabhusan@gmail.com
Dim service() As System.ServiceProcess.ServiceController Dim i As Integer service = System.ServiceProcess.ServiceController.GetServices() For i = 0 To service.Length - 1 If service(i).ServiceName = "wampapache" Then If service(i).Status = ServiceControllerStatus.Running Then ' Kill the Service service(i).Stop() Application.Exit() Else Dim startInfo As System.Diagnostics.ProcessStartInfo Dim pStart As New System.Diagnostics.Process startInfo = New System.Diagnostics.ProcessStartInfo("E:\Biswabhusan_Collection\COREPRACTICE\TestService\wamp5_1.6.1.exe") pStart.StartInfo = startInfo pStart.Start() pStart.WaitForExit() 'Your code will halt until the exe file has executed. End If End If Next solveed - Biswabhusan
-
Hi, take a look on the class ServiceController (include Reference System.ServiceProcess). Sample: ServiceController controller = new ServiceController(); controller.Refresh(); // Controller should read state if (controller.State == ServiceControllerStatus.Running) // Service is running... ... you will receive an exception if the specified service does not exist.
Thank you.