net start 服務名字
或者
類似
ServiceController sc = new ServiceController();
sc.ServiceName = "W3SVC";
if (sc.Status == ServiceControllerStatus.Stopped)
{
// Start the service if the current status is stopped.
Console.WriteLine("Starting the Alerter service...");
try
{
// Start the service, and wait until its status is "Running".
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running);
// Display the current service status.
Console.WriteLine("The www 服務 status is now set to {0}.",
sc.Status.ToString());
}
catch (InvalidOperationException)
{
Console.WriteLine("Could not start the Alerter service.");
}
}
記得添加對System.ServiceProcess.dll的引用
1.通過net start ,net stop 命令行程序在cmd中調用
2.使用System.ServiceProcess.ServiceController 類來操作。