开发者

how to turn windows service on if its off. control it from webapplication

开发者 https://www.devze.com 2023-02-16 00:42 出处:网络
i want to turn windows service on when it is off. is it possible to make via code from web application with开发者_JAVA技巧 c#?

i want to turn windows service on when it is off. is it possible to make via code from web application with开发者_JAVA技巧 c#? i am using asp.net mvc and c#.


You're looking for the ServiceController class.


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


Here an example:

                var sc = new ServiceController("Your service name");
                sc.Stop();
                sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(120));
                logger.Info("service stopped.");


Use the ServiceController class.

0

精彩评论

暂无评论...
验证码 换一张
取 消