I create a windows service controller. I use this code for stop a service.
private void button1_Click(object sender, EventArgs e)
{
ServiceController myService = new ServiceController();
myService.ServiceName = "BITS";
if ((myService.Status.Equals(ServiceControllerStatus.Running)) || (myService.Status.Equals(ServiceControllerStatus.StartPending)))
{
myService.Stop();
label1.Text = "Service is stop";
}
}
But when i click stop button. It show correct service status. But it is not working for stop this service. When i click there show a error message that
" An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceProcess.dll , Additional information: Cannot open BITS service on computer '.'. "
Anybody help me to solve this problem.