gpt4 book ai didi

c# - 如何在 C# mvc 中停止或启动 Windows 服务?

转载 作者:太空狗 更新时间:2023-10-29 20:16:15 28 4
gpt4 key购买 nike

我试过了 系统.ServiceProcess.ServiceController 系统.诊断.进程;

在我的网络表单中控制 Windows 服务。使用 System.ServiceProcess.ServiceController 我得到拒绝访问异常。

使用 System.Diagnostics.Process 我什么也得不到。知道如何使用 Web 表单启动/停止 Windows 服务吗?

最佳答案

Here are the important points to accomplish:

1 You need to addSystem.ServiceProcess reference in your application. This namespaceholds ServiceController Class to access the window service.

2 You need to check the status of the window services before youexplicitly start or stop it.

3 By default, IIS application runs under ASP.NET account whichdoesn't have access rights permission to window service. So, VeryImportant part of the solution is: Impersonation. You need toimpersonate the application/part of the code with the User Credentialswhich is having proper rights and permission to access the windowservice.

请参阅 asp.net 中的此博客条目还要看看这个 https://stackoverflow.com/a/17497084/1641556

关于c# - 如何在 C# mvc 中停止或启动 Windows 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36936157/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com