简体   繁体   English

Windows窗体应用程序的提取过程中拒绝访问

[英]Access denied on Windows Forms Application fetching process.startTime

I am trying to print Windows all processes names, startTime and EndTime. 我正在尝试打印Windows所有进程名称,startTime和EndTime。

private void loadProcessList()
{
    label1.Visible = false;
    listView1.Items.Clear();
    Process[] processList = Process.GetProcesses();
    foreach (Process process in processList)
    {
        ListViewItem item = new ListViewItem(process.ProcessName);
        item.Tag = process;
        DateTime started = process.StartTime;
        string[] row1 = { "Running", started.ToString(), "00:00" };
        listView1.Items.Add(item).SubItems.AddRange(row1);
       }
    }

process.ProcessName is working fine. process.ProcessName运行正常。 But when I try to fetch the process startTime or EndTime I get this error: 但是,当我尝试获取进程startTime或EndTime时,出现此错误:

错误信息

If you make sure that the user has the PROCESS_QUERY_LIMITED_INFORMATION access right, that should be enough to fix the Access denied exception. 如果您确定用户具有PROCESS_QUERY_LIMITED_INFORMATION访问权限,则该权限应足以修复“拒绝访问”异常。 However, if you don't have control over the access rights, you should try to use WMI (Windows Management Instrumentation) to get the process information. 但是,如果您无法控制访问权限,则应尝试使用WMI (Windows管理规范)来获取过程信息。

You basically use a query language to get the information you want from the processes running on the computer. 基本上,您使用查询语言从计算机上运行的进程中获取所需的信息。 Here's an example of how to use it: 以下是使用方法的示例:

Process Information and Notifications using WMI 使用WMI处理信息和通知

The article is pretty old but WMI still works the same way in newer versions of Windows. 这篇文章已经很老了,但是WMI在新版本的Windows中仍然以相同的方式工作。 You might still need to do modifications but in the best case, the code will work for you as it is. 您可能仍需要进行修改,但是在最佳情况下,该代码将按原样为您工作。

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

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