如何获取当前窗口的进程路径,并打开所属文件夹 Topic is solved
Moderators: tmplinshi, arcticir
如何获取当前窗口的进程路径,并打开所属文件夹
刚学,查了下文档,好像是用winget,但是写完后发现不对,想问下具体写法,然后自己如何debug
Re: 如何获取当前窗口的进程路径,并打开所属文件夹
stolen from v2
Code: Select all
GetProcessPath(PID) {
static PROCESS_QUERY_LIMITED_INFORMATION := 0x1000
if !hProcess := DllCall("OpenProcess", "UInt", PROCESS_QUERY_LIMITED_INFORMATION, "Int", false, "UInt", PID, "Ptr")
throw Exception("OpenProcess failed with " A_LastError, -1, PID)
static MAX_PATH := 260
static pathSize := (MAX_PATH + 1) * (A_IsUnicode ? 2 : 1)
VarSetCapacity(szImageFileName, pathSize, 0)
if !DllCall("psapi\GetProcessImageFileName", "Ptr", hProcess, "Str", szImageFileName, "UInt", pathSize, "UInt")
{
DllCall("CloseHandle", "Ptr", hProcess)
throw Exception("GetProcessImageFileName failed with " A_LastError, -1)
}
static DriveLetters := StrSplit("A: B: C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:", A_Space)
for each, letter in DriveLetters
{
VarSetCapacity(szDevicePath, pathSize, 0)
if !DllCall("QueryDosDevice", "Str", letter, "Str", szDevicePath, "UInt", pathSize, "UInt")
continue
processPath := letter RegExReplace(szImageFileName, "^\Q" szDevicePath "\E", , cReplacements)
if cReplacements
{
DllCall("CloseHandle", "Ptr", hProcess)
return processPath
}
}
DllCall("CloseHandle", "Ptr", hProcess)
}
Re: 如何获取当前窗口的进程路径,并打开所属文件夹 Topic is solved
这个比相比 winget 有什么优点吗?
回楼主
Code: Select all
#F1::
WinGet, OutputVar, ProcessPath, A
MsgBox, %OutputVar%
Return
Who is online
Users browsing this forum: No registered users and 9 guests