在System.Diagnostics.Process.GetProcesses()上拒绝Acess [英] Acess Denied on System.Diagnostics.Process.GetProcesses()

查看:363
本文介绍了在System.Diagnostics.Process.GetProcesses()上拒绝Acess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个代码来计算所有进程计算机以及我在每个进程上花费的时间。



当我开始调试以下代码时我尝试获取processStartTime时抛出异常。



消息是Acess Denied。



p.StartTime'p.StartTime'抛出类型'System.ComponentModel.Win32Exception'的异常



em System.Diagnostics.ProcessManager.OpenProcess(Int32 processId,Int32 access,Boolean throwIfExited)

em System.Diagnostics.Process.GetProcessHandle(Int32 access,Boolean throwIfExited)

em System.Diagnostics.Process.GetProcessTimes()

em System.Diagnostics.Process.get_StartTime()





任何人都可以帮助我吗?



祝你好运



I am trying to write a code to counting all the process machine and the time spent by me on each process.

When i start to debug the following code below an exception has throw when i try to get the processStartTime.

The message is "Acess Denied".

p.StartTime 'p.StartTime' threw an exception of type 'System.ComponentModel.Win32Exception'

em System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited)
em System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited)
em System.Diagnostics.Process.GetProcessTimes()
em System.Diagnostics.Process.get_StartTime()


Anyone can help me ?

Best regards

var list = System.Diagnostics.Process.GetProcesses();
           foreach (var p in list)
           {
               System.Diagnostics.PerformanceCounter pc = new System.Diagnostics.PerformanceCounter();

               string processStartTime = string.Empty;
               if (p.StartTime != null)
                   processStartTime = p.StartTime.ToString();
               listbox1.Items.Add(p.ProcessName + " MainWindowHandle: " + p.MainWindowTitle + " process start time: " + processStartTime);
           }

推荐答案

1.您应具有管理员权限才能访问流程信息。



2.解决方案是以管理员身份运行您的应用程序。
1.You should have Administrator rights in order to can access the process info.

2.The solution is to run your application "As Administrator".


这篇关于在System.Diagnostics.Process.GetProcesses()上拒绝Acess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆