Process.StartTime 访问被拒绝
我的代码需要确定特定进程已经运行了多长时间。 但它仍然失败,并在 Process.StartTime
请求上出现访问被拒绝的错误消息。 这是一个使用用户凭据运行的进程(即不是高权限进程)。 显然有一个安全设置或策略设置,或者我需要摆弄一些东西来解决这个问题,因为我不敢相信 StartTime 属性在框架中只是为了让它 100% 失败的时间。
Google 搜索表明,我可以通过将运行查询代码的凭据的用户添加到“性能日志用户”组来解决此问题。 但是,该计算机上不存在这样的用户组。
My code needs to determine how long a particular process has been running. But it continues to fail with an access denied error message on the Process.StartTime
request. This is a process running with a User's credentials (ie, not a high-privilege process). There's clearly a security setting or a policy setting, or something that I need to twiddle with to fix this, as I can't believe the StartTime property is in the Framework just so that it can fail 100% of the time.
A Google search indicated that I could resolve this by adding the user whose credentials the querying code is running under to the "Performance Log Users" group. However, no such user group exists on this machine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我可以枚举该进程(即 GetProcessById 函数有效),并且我们还有其他代码来获取 EXE 名称和其他信息位。
我会尝试一下测试应用程序。 如果我无法在短时间内使 C# 实现正常工作,我还将尝试使用 WMI 来获取此信息(这不是关键功能,因此我不能花几天时间在上面)。
I can enumerate the process (ie, the GetProcessById function works), and we have other code that gets the EXE name and other bits of information.
I will give the test app a try. I'm also going to attempt to use WMI to get this information if I can't get the C# implementation working properly in short order (this is not critical functionality, so I can't spend days on it).
底层代码需要能够调用 OpenProcess,为此您可能需要 SeDebugPrivilege。
您正在执行 StartTime 请求的进程是否以与您自己的进程不同的用户身份运行?
The underlying code needs to be able to call OpenProcess, for which you may require SeDebugPrivilege.
Is the process you're doing the StartTime request on running as a different user to your own process?
好的,抱歉,这不起作用...我不是 ASP.NET 模拟方面的专家,我倾向于使用应用程序池,我认为您无法在 W2K 上做到这一点。您是否尝试过编写一个小型测试应用程序来执行以下操作相同的查询,然后以不同的用户身份运行?
我不愿意在这里发布一大块 MS 框架代码,但您可以使用 Reflector 或这个: http:// www.codeplex.com/NetMassDownloader 获取框架相关部分的源代码,以便您可以尝试实现各种部分以查看失败的地方。
您能否在不被拒绝访问的情况下获得有关该过程的任何其他信息?
OK, sorry that didn't work... I am no expert on ASP.NET impersonation, I tend to use app pools which I don't think you can do on W2K Have you tried writing a tiny little test app which does the same query, and then running that as various users?
I am reluctant to post a chunk of MS framework code here, but you could use either Reflector or this: http://www.codeplex.com/NetMassDownloader to get the source code for the relevant bits of the framework so that you could try implementing various bits to see where it fails.
Can you get any other info about the process without getting Access Denied?
.Net 1.1 的进程使用性能计数器来获取信息。 它们要么被禁用,要么用户没有管理权限。 确保启用性能计数器并且用户是管理员应该可以使您的代码正常工作。
实际上“性能计数器用户组”应该足够了。 默认情况下该组不存在。 所以你应该自己创建它。
.Net 2.0 的进程不依赖于性能计数器。
请参阅http://weblogs.asp.net/nunitaddin/archive /2004/11/21/267559.aspx
Process of .Net 1.1 uses the Performance Counters to get the information. Either they are disabled or the user does not have administrative rights. Making sure the Performance Counters are enabled and the user is an administrator should make your code work.
Actually the "Performance Counter Users Group" should enough. The group doesn't exist by default. So you should create it yourself.
Process of .Net 2.0 is not depended on the Performance Counters.
See http://weblogs.asp.net/nunitaddin/archive/2004/11/21/267559.aspx
我读过一些与你过去所说的类似的内容,拉斯。 不幸的是,我对有问题的机器能做的事情有些限制(换句话说,我不能随意创建用户组:它是一台服务器,而不仅仅是一些随机的 PC)。
感谢威尔和拉尔斯的回答。 不幸的是,他们没有解决我的问题。
最终的解决方案是使用 WMI:
其中部分内容是从代码项目中删除的:
http:// /www.codeproject.com/KB/system/win32processusingwmi.aspx
和“嘿,脚本专家!”:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul05/hey0720.mspx
I've read something similar to what you said in the past, Lars. Unfortunately, I'm somewhat restricted with what I can do with the machine in question (in other words, I can't go creating user groups willy-nilly: it's a server, not just some random PC).
Thanks for the answers, Will and Lars. Unfortunately, they didn't solve my problem.
Ultimate solution to this is to use WMI:
Parts of this were scraped from Code Project:
http://www.codeproject.com/KB/system/win32processusingwmi.aspx
And "Hey, Scripting Guy!":
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul05/hey0720.mspx