The last time I published a "C # control" Ms-sqlserver service to start and stop, most of its content is collected online, today it refined. So the topic is as above.
In fact, all the services in the computer can be controlled by the computer, such as: IIS, Ms-sql Server and other services, we want to control its start and stop only need to find the service corresponding to the service name.
Steps: Right-click My Computer--> management-->--> Services and Applications--> in the Computer Management window Select Services--> Find the service you want to control right-click to select "Properties"--> on the General tab, "server name" One item (remember it, this is the name of the service you want)
Here's what you'll do in VS2005:
First, to add a reference system.serviceprocess
Second, you want to use namespaces in your program ServiceProcess
Code fragment:
Using System.ServiceProcess;
ServiceController serviceController1 = new ServiceController ();
Servicecontroller1.servicename = "server name";
Servicecontroller1.machinename = ".";
if (Servicecontroller1.status = = servicecontrollerstatus.running)
Servicecontroller1.stop ();
Else
Servicecontroller1.start ();