title: GetModuleFileNameEx Function returns wrong path of system processes
body: <p>In my WPF project, I am receiving the path of the currently running process via the <a href="http://msdn.microsoft.com/en-us/library/ms683198%28VS.85%29.aspx" rel="nofollow noreferrer"><strong>GetModuleFileNameEx</strong></a> method. It works in most cases, but for example when the currently running process is "Windows Explorer" (a <strong>system process</strong>), I get "C$Å" (and other random characters).</p>
  
  <p>Delphi developers had a similar problem <a href="https://stackoverflow.com/questions/6771682/not-getting-path-of-various-system-processes-by-getmodulefilenameex">here</a> and <a href="https://stackoverflow.com/questions/25063530/why-do-i-get-nonsense-from-getmodulefilenameex-on-64-bit-windows-8">here</a>. The first problem was solved by setting a debug privilege. Unfortunately, It seems, this doesn't help me <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff541528(v=vs.85).aspx" rel="nofollow noreferrer">in C#</a>...</p>
  
  <p>This is the method:</p>
  
  <pre><code>[DllImport("psapi.dll", SetLastError = true)]
  private static extern int GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, int nSize);
  </code></pre>
  
  <p>Here I call the method:</p>
  
  <pre><code>// Get module file name
  var buffer = new StringBuilder(4096);
  GetModuleFileNameEx(hProcess, IntPtr.Zero, buffer, buffer.Capacity);
  process = buffer.ToString();
  </code></pre>
  
  <p>Did anyone face similar problems or has an idea how to solve this issue? Thanks.</p>
  
  <p>Btw, I am running a Windows 8.1, 64bit machine.</p>