Triven
Triven

Reputation: 351

ahk run pid is not same as shown in Window Spy

I am trying to capture PID from Run command and use the PID to resize window. But no luck. After spending several hours I realized that PID shown in message box different from PID inspected via Spy Window. Any suggestion?

Run, "C:\Program Files\Git\git-bash.exe",,, PID
;Sleep, 300
MsgBox, %PID% is the process PID ; --> PID shown here is different from PID inspected via Window Spy
WinWait, ahk_pid %PID%
;Sleep, 300
;WinActivate, ahk_pid %PID%
WinMinimize, ahk_pid %PID%
;WinMove, ahk_pid %PID%, ,500, 250, 200, 100
return

Upvotes: 0

Views: 582

Answers (1)

0x464e
0x464e

Reputation: 6489

It's because the window that appears, doesn't come from the git-bash.exe process.
It comes from mintty.exe, which gets launched somewhere down the line after you run git-bash.exe.

Most simple thing you can do, is wait for the window to appear after launching git-bash.exe, like so:

Run, % "C:\Program Files\Git\git-bash.exe"
;// sleep a bit because other things from mintty.exe seem to get lauched first as well
Sleep, 1000
WinWait, % "ahk_exe mintty.exe"
;// get the hwnd of the last found window (the window we waited for above)
hwnd := WinExist()

;// and if you for some reason really need the PID, you can do e.g this to get it
WinGet, pid, PID, % "ahk_id " hwnd
MsgBox, % pid

Upvotes: 1

Related Questions