简体   繁体   English

在Web应用程序上以C#查询Windows服务状态

[英]Querying a Windows Service status in C# on a Web Application

We are using the ServiceController object to query if our Service is running or not. 我们正在使用ServiceController对象来查询我们的服务是否正在运行。 Our web application that is performing the query is using Impersonation for security/login. 我们正在执行查询的Web应用程序正在使用模拟来进行安全性/登录。

System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("myService");
return sc.Status

Using an Administrator account, the query is successful. 使用管理员帐户,查询成功。 Using a limited account (non-administrator), the query is failing with a message of "Service myService was not found on computer '.'"... BUT it is only failing in Windows Server 2003 and not in Windows XP. 使用受限帐户(非管理员),查询失败,并显示一条消息“在计算机'。'上未找到服务myService”。但是,它仅在Windows Server 2003中失败,而在Windows XP中失败。

I've Googled it and checked in MSDN. 我已经用Google搜索并签入了MSDN。 I didn't find anything related to the usage of ServiceController in Windows Server 2003. 我没有发现任何与Windows Server 2003中ServiceController的使用相关的信息。

Any ideas? 有任何想法吗?

EDIT: If there is a way to query the service status without using the ServiceController that doesn't involve "security" privileges, that might work for us. 编辑:如果有一种方法可以不使用不涉及“安全”特权的ServiceController来查询服务状态,则可能对我们有用。 We just need to get the status of the service. 我们只需要获取服务状态。

UPDATE: 更新:

I created a simple console application that will print the status of the service. 我创建了一个简单的控制台应用程序,它将打印服务的状态。 I used the "runas" command to run the application using both the Administrator and Non-Administrator account. 我使用“ runas”命令来使用管理员和非管理员帐户运行应用程序。 It both worked in Windows Server 2003... Which means that this is an issue of the privilege not being properly passed to the ServiceController call in the web application? 两者都可以在Windows Server 2003中使用。。。这意味着特权没有正确传递给Web应用程序中的ServiceController调用的问题? IIS security stuff perhaps? IIS安全的东西?

Thanks! 谢谢!

I thought that web app-s are supposed to be run in a sandbox. 我认为网络应用程序应该在沙箱中运行。 Allowing access to the service running on local computer isn't really what you should do, because of security issues. 由于安全问题,实际上不应该允许访问在本地计算机上运行的服务。

Maybe you could tell us what you want to do and there is another solution? 也许您可以告诉我们您想做什么,还有另一种解决方案?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM