i want to turn windows service on when it is off. is it possible to make via code from web application with c#? i am using asp.net mvc and c#.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You're looking for the ServiceController
class.
回答2:
Its possible to do it but its unlikely that you want to run your website under an account which has enough rights to be able to Start/Stop services. You can use the ServiceController class to start a service see here
回答3:
Here an example:
var sc = new ServiceController("Your service name");
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(120));
logger.Info("service stopped.");
回答4:
Use the ServiceController class.