我编写了一个 ASP.NET Web 应用程序,它显示了我们产品的所有已安装服务。我的应用程序可以检索服务状态(正在运行、已停止......)。
此外,我的应用程序应该能够启动已停止的服务并停止正在运行的服务。在我的本地机器上它可以工作,在服务器上它不能。目前我将网络应用程序配置为使用管理员,但它没有启动。事件查看器显示,访问被拒绝:
Process information:
Process ID: 5348
Process name: w3wp.exe
Account name: IIS APPPOOL\ServiceManager
Exception information:
Exception type: Win32Exception
Exception message: Access is denied
Request information:
Request URL: http://X/ServiceMonitor/StopService/25
Request path: /ServiceMonitor/StopService/25
User host address: X
User:
Is authenticated: False
Authentication Type:
Thread account name: X\Administrator
Thread information:
Thread ID: 23
Thread account name: X\Administrator
Is impersonating: False
Stack trace:
知道我错过了什么吗?
就像附加信息一样,这里是我的 StartService 功能。但应该不是问题,因为它可以在我的本地机器上运行:
public bool StartService()
{
ServiceController service = new ServiceController(_serviceName,_machineName);
if (!new[] { ServiceControllerStatus.Running, ServiceControllerStatus.StartPending }.Contains(service.Status))
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMinutes(2));
return service.Status == ServiceControllerStatus.Running;
}