c# - ASP.NET 以编程方式启动服务访问被拒绝
问题描述
我正在构建一个 ASP.NET MVC 应用程序,当用户以管理员身份登录(不是 Windows 身份验证,仅限此应用程序的管理员)时,他们需要能够启动和停止服务。每次我以编程方式尝试此操作时,我都会被拒绝访问,该服务作为本地系统运行。是否可以使用ServiceController
具有正确权限的特定用户来启动 Windows 服务?关于这个有几个线程,但没有一个回答我的问题。请参见下面的代码:
private static System.ServiceProcess.ServiceController svc = new System.ServiceProcess.ServiceController("CanCam Review Service");
public static void StartService()
{
string[] args = new string[] { Configuration.databaseConnectionString, Configuration.intervalInSeconds.ToString(), Configuration.packetLimit.ToString(), Configuration.suspectedHackTimeOutInSeconds.ToString(), Configuration.writeToFile.ToString(), Configuration.path, Configuration.maxFileAgeInDays.ToString() };
if (serviceStatus == ServiceControllerStatus.Stopped)
svc.Start(args);
}
解决方案
推荐阅读
- php - 在 PHP 中验证以太坊(Web3)签名的消息
- java - Spring data JPA 使用 Beanutils.copyProperties 更新一对多关系
- python - 我可以使用 Firebase 函数来接收应该发送到端口上的服务器的数据吗?
- python - 在python中将首字母与全名输入分开而不使用split
- assembly - 如何从 qword(四字)中减去 dword(双字)?
- php - 双 URL 触发器创建 move_uploaded_file() 失败
- python - 无法让小部件更新其大小
- python - 如何在gyame中同时移动一个班级的多个实例
- python - 从 yahoo.finance 中提取数据
- python - 用python渲染jpg字节数组序列