Why can`t I get the path of the process(retrieved by GetWindowThreadProcessId+OpenProcess) which create the desktop window (retrieved by GetDesktopWindow) by GetModuleFileNameEx?
#include <stdio.h>
#include <windows.h>
#pragma comment (lib, "user32.lib")
#include <Psapi.h>
#pragma comment(lib,"Kernel32.lib")
main(){
FILE *fp = fopen("C:/windowLog.txt", "a");
HWND desktopWindow=GetDesktopWindow();
fprintf(fp, "Handle of Desktop window is%x\n", (unsigned int)desktopWindow);
CHAR dName[MAX_PATH] = { 0 };
GetWindowTextA(desktopWindow, dName, MAX_PATH);
fprintf(fp, "Title of desktop window is %s\n", dName);
GetClassName(desktopWindow, dName, MAX_PATH);
fprintf(fp, "Desktop window class is %s\n", dName);
DWORD pid = 0;
GetWindowThreadProcessId(desktopWindow, &pid);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
CHAR path[260] = { 0 };
GetModuleFileNameEx(hProcess, NULL, path, 260);
fprintf(fp, "The path of the process is %s\n\n", path);
fclose(fp);
I can't get the path from GetModuleFileNameEx.
What I have tried:
GetDesktopWindow + GetWindowThreadProcessId + OpenProcess + GetModuleFileNameEx