Author: Aamir Hasan
ServiceController class to control the SimpleService service.
Add reference to System.ServiceProcess.
Namespace: System.ServiceProcess
Assembly: System.ServiceProcess (in System.ServiceProcess.dll)
C#
static void Main(string[] args)
{
try
{
ServiceController controller = new ServiceController("SERVICENAME");
if (controller.Status.Equals(ServiceControllerStatus.Running)
&& controller.CanStop)
{
controller.Stop();
Console.WriteLine("Service Stopped");
}
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
VB.NET
Shared Sub Main(ByVal args() As String)
Try
Dim controller As New ServiceController("SERVICENAME")
If controller.Status.Equals(ServiceControllerStatus.Running)_
AndAlso controller.CanStop Then
controller.Stop()
Console.WriteLine("Service Stopped")
End If
Console.ReadLine()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Reference http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx
Author:
Aamir Hasan औथोर:
आमिर हसन أثر
أمير حسن .
079cbcd6-494b-44c2-88e4-c5c0390fcad5|0|.0
ALL, .NET
window services