how to turn windows service on if its off. control

2019-02-17 15:38发布

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#.

4条回答
太酷不给撩
2楼-- · 2019-02-17 16:20
趁早两清
3楼-- · 2019-02-17 16:25

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

查看更多
▲ chillily
4楼-- · 2019-02-17 16:32

You're looking for the ServiceController class.

查看更多
干净又极端
5楼-- · 2019-02-17 16:39

Here an example:

                var sc = new ServiceController("Your service name");
                sc.Stop();
                sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(120));
                logger.Info("service stopped.");
查看更多
登录 后发表回答