title: Getting an executing processes full path in Windows XP
body: <p>So i need to get a list of processes running on a computer and then get the full path of each process. (Im looking for the folder each process is run from). I was using QueryFullProcessImageName - <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684919(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/ms684919(v=vs.85).aspx</a> however ive only just found out that this code needs to work on Windows XP and that functions minimum client is Vista. </p>
  
  <p>So does anyone know of another way of doing this?</p>
  
  <p>I was trying to use GetModuleFileNameEx but it just wouldnt work. I would pass in the Process handle and all i would get back in the output was "íííííííííííííííííííííííííííííííííííí".</p>
  
  <p>EDIT: Here was my attempt to use GetModuleFileNameEx:</p>
  
  <pre><code>HANDLE hProcessSnap;
  PROCESSENTRY32 pe32;
  string name = procName;
  
  // Take a snapshot of all processes in the system.
  hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if (hProcessSnap == INVALID_HANDLE_VALUE)
  {
      REPORT_ERROR("CreateToolhelp32Snapshot (of processes): err=%d\n", ::GetLastError());
      return false;
  }
  
  // Set the size of the structure before using it.
  pe32.dwSize = sizeof(pe32);
  
  // Retrieve information about the first process,
  // and exit if unsuccessful
  if( !Process32First(hProcessSnap, &amp;pe32))
  {
      REPORT_ERROR("Process32First: err=%d\n", ::GetLastError());  // Show cause of failure
      CloseHandle(hProcessSnap);     // Must clean up the snapshot object!
      return false;
  }
  char pName[MAX_PATH];
  
  //iterate through all processes
  do {
      //Find start of files name
      char *szProcessFilename = strchr(pe32.szExeFile, '\\');
      if (szProcessFilename == NULL)
          szProcessFilename = pe32.szExeFile;
      else
          szProcessFilename++;    //Skip over last slash
  
      if (_stricmp(procName, szProcessFilename) == 0)
      {
          HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION, false, pe32.th32ProcessID );
          char procLocationChar[MAX_PATH];
          DWORD exe_path_size = MAX_PATH;
          DWORD s = GetModuleFileNameEx(hProcess, NULL, pName, exe_path_size);
  </code></pre>
  
  <p>I do some more stuff after this to get the path, but the value of pName is just "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"</p>