;~ ; Example #2: 访问整个系统上所有窗口并显示它们的信息: ;~ WinGet, id, list,,, Program Manager ;~ Loop, %id% ;~ { ;~ this_id := id%A_Index
;~ ; Example #2: 访问整个系统上所有窗口并显示它们的信息:
;~ WinGet, id, list,,, Program Manager
;~ Loop, %id%
;~ {
;~ this_id := id%A_Index%
;~ WinActivate, ahk_id %this_id%
;~ WinGetClass, this_class, ahk_id %this_id%
;~ WinGetTitle, this_title, ahk_id %this_id%
;~ MsgBox, 4, , Visiting All Windows`n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n`nContinue?
;~ IfMsgBox, NO, break
;~ }
;~ Gui, Add, ListView, x2 y0 w400 h500, Process Name|Command Line
;~ for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
;~ LV_Add("", process.Name, process.CommandLine)
;~ Gui, Show,, Process List
; 示例 #4: 使用 DllCall 获取正在运行的进程列表然后显示在 MsgBox.
d := " | " ; 字符串分隔符
s := 4096 ; 缓存和数组的大小 (4 KB)
Process, Exist ; 设置 ErrorLevel 为这个正在运行脚本的 PID
; 使用 PROCESS_QUERY_INFORMATION (0x0400) 获取此脚本的句柄
h := DllCall("OpenProcess", "UInt", 0x0400, "Int", false, "UInt", ErrorLevel, "Ptr")
; 打开此进程的可调整的访问令牌 (TOKEN_ADJUST_PRIVILEGES = 32)
DllCall("Advapi32.dllOpenProcessToken", "Ptr", h, "UInt", 32, "PtrP", t)
VarSetCapacity(ti, 16, 0) ; 特权结构
NumPut(1, ti, 0, "UInt") ; 特权数组中的一个条目...
; 获取调试特权的本地唯一标识符:
DllCall("Advapi32.dllLookupPrivilegeValue", "Ptr", 0, "Str", "SeDebugPrivilege", "Int64P", luid)
NumPut(luid, ti, 4, "Int64")
NumPut(2, ti, 12, "UInt") ; 启用这个特权: SE_PRIVILEGE_ENABLED = 2
; 使用新的访问令牌更新此进程的特权:
r := DllCall("Advapi32.dllAdjustTokenPrivileges", "Ptr", t, "Int", false, "Ptr", &ti, "UInt", 0, "Ptr", 0, "Ptr", 0)
DllCall("CloseHandle", "Ptr", t) ; 关闭此访问令牌句柄以节约内存
DllCall("CloseHandle", "Ptr", h) ; 关闭此进程句柄以节约内存
hModule := DllCall("LoadLibrary", "Str", "Psapi.dll") ; 通过预加载来提升性能
s := VarSetCapacity(a, s) ; 接收进程列表标识符的数组:
c := 0 ; 用于进程标识符的计数器
DllCall("Psapi.dllEnumProcesses", "Ptr", &a, "UInt", s, "UIntP", r)
Loop, % r // 4 ; 把数组解析为 DWORD (32 位) 的标识符:
{
id := NumGet(a, A_Index * 4, "UInt")
; 打开进程: PROCESS_VM_READ (0x0010) | PROCESS_QUERY_INFORMATION (0x0400)
h := DllCall("OpenProcess", "UInt", 0x0010 | 0x0400, "Int", false, "UInt", id, "Ptr")
if !h
continue
VarSetCapacity(n, s, 0) ; 接收模块基础名称的缓存:
e := DllCall("Psapi.dllGetModuleBaseName", "Ptr", h, "Ptr", 0, "Str", n, "UInt", A_IsUnicode ? s//2 : s)
if !e ; 用于 64 位进程在 32 位模式时的回退方法:
if e := DllCall("Psapi.dllGetProcessImageFileName", "Ptr", h, "Str", n, "UInt", A_IsUnicode ? s//2 : s)
SplitPath n, n
DllCall("CloseHandle", "Ptr", h) ; 关闭进程句柄以节约内存
if (n && e) ; 如果映像不是空的, 则添加到列表:
l .= n . d, c++
}
DllCall("FreeLibrary", "Ptr", hModule) ; 卸载库来释放内存
;Sort, l, C ; 取消注释这行来按字母顺序对列表进行排序
MsgBox, 0, %c% Processes, %l%
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

