3

I am listing all running processes in system with it full path. My application is running fine in XP but in vista, it gives access denied exception while accessing MainModule.FileName. (Due to UAC, i think).

  foreach (Process process in Process.GetProcesses())
{
    sProcess = process.ProcessName;
    sFullpath = process.MainModule.FileName; 
..
..
..
  }

I did not find a solution to deal with UAC. Any clue??

Manjoor
  • 4,091
  • 10
  • 43
  • 67

2 Answers2

2

It may not be UAC at all. It may be that your process is x32 and the process being queried is x64 or vice versa. process.MainModule seems to choke when that happens with a Win32Exception, "Only part of a ReadProcessMemory or WriteProcessMemory request was completed"

Could that be it?

DJA
  • 661
  • 1
  • 9
  • 25
  • I had the same issue today. Seems setting the Target platform to Any solved it for me. – Philip Fourie Jun 24 '10 at 05:24
  • Is it possible to overcome this when Target is x86 (using some 32 bit dlls which fail to work in 64 bit mode) and the app is running on x64? – Muxa Aug 22 '10 at 09:44
0

To add to DJA's answer, Process.MainModule is using the EnumProcessModules API:

If the module list in the target process is corrupted or not yet initialized, or if the module list changes during the function call as a result of DLLs being loaded or unloaded, EnumProcessModules may fail or return incorrect information

So you may be trying to use this function while the target process is unstable, getting ERROR_PARTIAL_COPY (299).

Shmuel Fomberg
  • 546
  • 2
  • 11