Find process associated with window
Is there any way in NSIS to find out the ProcessID (and/or ProcessName) associated with a particular window returned by FindWindow?
7 posts
Section "ListWindowsInfo"
FileOpen $8 "c:\temp\windowslist.txt" "w"
SetPluginUnload alwaysoff
System::Get "(i.r1, i) iss"
Pop $R0
System::Call "user32::EnumWindows(k R0, i) i.s"
loop:
Pop $0
StrCmp $0 "callback1" 0 done
System::Call "user32::GetWindowText(ir1,t.r2,i${NSIS_MAX_STRLEN})"
System::Call "user32::GetClassName(ir1,t.r3,i${NSIS_MAX_STRLEN})"
System::Call "user32::GetWindowModuleFileName(ir1,t.r6,i${NSIS_MAX_STRLEN})"
System::Call "user32::GetWindowThreadProcessId(ir1,i.r7) i .r9"
IntFmt $4 "0x%X" $1
FileWrite $8 "$1 / $4 - [$3] $2$\r$\n"
FileWrite $8 " $1 -->> FileName: $6$\r$\n"
FileWrite $8 " $1 -->> Thread: $9$\r$\n"
FileWrite $8 " $1 -->> Process: $7$\r$\n"
Push 1 # callback's return value
System::Call "$R0"
Goto loop
done:
SetPluginUnload manual
System::Free $R0
FileClose $8
SectionEnd I'm a bit lost...GetWindowModuleFileName returns the name of a EXE or DLL that created a window. Be forewarned though; this API only works on HWNDs created by the process that called the API. This means it’s only of use for windows that your program created or within a systemwide hook procedure.and I wonder if this is the reason for the above behavior
Originally posted by CancerFaceI found that one, I should have used a pointer:
Strange, although the threads are picked it seems that the process is always 0.
System::Call "user32::GetWindowThreadProcessId(ir1,*i.r7) i .r9" However the filename is not always the name of the NSIS script, there are some instances of comctl32.dll. I have no clue why!I read the same thing and will have to agree with you on that one.
The only thing I managed to dig out is this:
and I wonder if this is the reason for the above behavior
You get the window name that you're after, the Process ID of the process that created it and the filename of the executable responsible for that process ...
Section "ListWindowsInfo"
FileOpen $8 "c:\tempwindowslist.txt" "w"
SetPluginUnload alwaysoff
System::Get "(i.r1, i) iss"
Pop $R0
System::Call "user32::EnumWindows(k R0, i) i.s"
loop:
Pop $0
StrCmp $0 "callback1" 0 done
System::Call 'user32::GetWindowText(ir1,t.r2,i${NSIS_MAX_STRLEN})i.R6'
System::Call 'user32::GetClassName(ir1,t.r3,i${NSIS_MAX_STRLEN})i.R6'
System::Call 'user32::GetWindowThreadProcessId(ir1,*i.r7)i.r9'
System::Call 'kernel32::OpenProcess(i 0x1F0FFF,i0,ir7)i.R9'
System::Call 'Psapi::GetModuleFileNameExA(iR9,in,t.R8,i${NSIS_MAX_STRLEN})i.R6'
System::Call 'kernel32::CloseHandle(iR9)i.R6'
IntFmt $4 "0x%X" $1
FileWrite $8 "$1 / $4 - [$3] $2$\r$\n"
FileWrite $8 " $1 -->> Thread: $9$\r$\n"
FileWrite $8 " $1 -->> Process: $7$\r$\n"
FileWrite $8 " $1 -->> FileName: $R8$\r$\n"
Push 1 # callback's return value
System::Call "$R0"
Goto loop
done:
SetPluginUnload manual
System::Free $R0
FileClose $8