How can I start or stop system service like MSSQLSERVER?
How can I start or stop system service like MSSQLSERVER?
Normally I start system service in command line 'net start MSSQLSERVER'
How can I start or stop a service with C#? Certainly before you start a service we should detect if the service have been started, how to detect in C#?
[304 byte] By [
CUIWEI] at [2007-12-16]
Hi Cui Wei,
you can use:
System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("MSSQLSERVER");
sc.Start();
sc.Stop();
use:
System.ServiceProcess.ServiceController scc[] = System.ServiceProcess.ServiceController.GetServices();
to get an array of all local services.
HTH,
SvenC
Ops sorry.
ServiceController is there!
eg
System.ServiceProcess.
ServiceController sc = new System.ServiceProcess.ServiceController("Service name");
sc.Start();
sc.Stop();You just have to add a reference to System.ServiceProcess.dll
I did that, worked fine.