I'm trying to get executable path of process on Windows
OS. I have window handle coming from some windows event, from window handle I can acquire process id using GetWindowThreadProcessId()
. Then, according to windows api docs I can use OpenProcess()
function to make process handle and then with this use GetModuleFileNameExA()
or GetModuleFileNameExW()
for unicode characters to get process executable path. But sadly, in windows
crate I can't find none of this functions.
I tried to use GetWindowModuleFileNameW()
, but this works only for process that is calling this function or processes that come from this process (that's might be not exact explanation, but the way I understand it).
I found this functions in winapi
crate, but as I was suggested earlier, I better use windows
crate because its still maintained unlike winapi
.
Also I found kind of way to do this with sysinfo
crate, but if possible, I would like to not bring it just for this.
Any help will be appreciated!
UPD: There is OpenProcess()
function available after I installed rest of windows
crate features, but this still can't help me much without GetModuleFileNameExW()
UPDD: I found feature in windows
crate called Win32_System_ProcessStatus
which contains necessary functions. My problem is solved and I leave this here in case anybody will have same question.
The
windows
crate, like the API it provides bindings for, is massive. It comprises quite literally hundreds of thousands of line of code. To tame compile times, the crate is split into modules, each gated behind a feature.To use any given API binding, client code needs to enable the respective feature(s). The documentation lists the required feature(s) for every public constant, type, or function.
GetWindowThreadProcessId
:OpenProcess
:GetModuleFileNameExW
:To implement this program, the Cargo.toml file must contain the following table: