Process类对performance counter 有一个依赖,当某种原因在你的机器上performance counter 被禁时,Process.GetProcesses()就会抛出此异常
你将注册表的
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfProc\Performance]
增加键,"Disable Performance Counters",值为dword:00000000
然后就应该好了。

解决方案 »

  1.   

    就Process[] allProcesses = Process.GetProcesses();而言
    是一点错都没有的
      

  2.   

    可能是在注册表里被禁了,你可以查找如下的一个注册表项
    SYSTEM\CurrentControlSet\Services\PerfProc\Performance
    把Disable Performance Counters设为0或用如下的代码来做:RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\PerfProc\Performance", true);
    if (rk!=null)
    {
    object tmpObj=rk.GetValue("Disable Performance Counters");
    if (tmpObj!=null && !tmpObj.Equals(0))
    {
    rk.SetValue("Disable Performance Counters",0);
    }
    }
    System.Diagnostics.Process[] pros=System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName);