how to get FileName of process.MainModule?

后端 未结 1 1464
逝去的感伤
逝去的感伤 2021-01-27 07:29
Process[] processlist = Process.GetProcesses();
foreach (Process proc in processlist) {
              Console.Write(proc.MainModule.FileName);
}

it giv

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-27 08:02

    There are some processes that you aren't allowed to access even as administrator. You can trap the exception and keep going:

    foreach (Process proc in processlist)
    {
      try
      {
        Console.WriteLine(proc.MainModule.FileName);
      }
      catch (Win32Exception e)
      {
         Console.WriteLine(proc.ToString() + "  " + e.Message);
      }
    }
    

    0 讨论(0)
提交回复
热议问题