I'm writing an app that does actions depending on the current context. My goal is to get the path for the EXE that's currently running in the foreground. For this to work, I need to get the process handle for the foreground window. The problem is, with GetForegroundWindow()
I get back a window handle, and for OpenProcess()
to work I need to pass in a process ID, not a window handle. Any suggestions?
The code I'm currently using:
SetPrivilege(); //setting SE_DEBUG_NAME privilige for getting process path
DWORD processId = GetProcessId(GetForegroundWindow());
std::cout << "PID: " << processId << '\n'; //for debug
std::string ret;
HANDLE handle = OpenProcess(
PROCESS_QUERY_LIMITED_INFORMATION,
FALSE,
processId
);