How can I get the process file name under Vista?

I have an application that helps people with disabilities. For work, it keeps track of which window is in the foreground. I usually use this function to get the process executable.

bool GetWindowProcessExe2(HWND hwnd, wxString& process_exe)  
                       //LPTSTR buf, DWORD size)
{
DWORD result = 0;
DWORD pid = 0;
GetWindowThreadProcessId(hwnd, &pid);
if (HANDLE process =
    OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid))
{
  char buff[512];
  LPTSTR pbuff = buff;
  result = GetModuleFileNameEx(process, 0, pbuff, 512);
  if(result == 0)
  {
    //failed.
    wxLogError("GetModuleFileNameEx failed with error code %d", GetLastError());
  }
  CloseHandle(process);
  process_exe = fromCString(pbuff);
}

return result > 0 ? true : false;

}

, Vista (, "" > "" ), GetModuleFileNameEx() 299, , . , , ( ). , . ? , . ?

+3
2

, , 299 ERROR_PARTIAL_COPY, , .

Vista QueryProcessImageFileName PROCESS_QUERY_LIMITED_INFORMATION - .

WCHAR exeName[512];
DWORD cchExeName = 512;
HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid);
QueryFullProcessImageName(process, 0, exeName, &cchExeName);

EDIT: ERROR_PARTIAL_COPY , 64-, , 32-. 64-/64- .

+2

, 32- GetModuleFileNameEx 32- . 64- , ERROR_PARTIAL_COPY. 64- 64- 64- , GetModuleFileNameEx 64, 32- .

+1

Source: https://habr.com/ru/post/1705520/


All Articles