进程函数

用于检索信息, 或对进程执行各种操作的函数. 单击函数名查看详细信息.

函数 描述
ProcessClose 强制关闭第一个匹配的进程.
ProcessExist 检查指定的进程是否存在.
ProcessGetName 返回指定进程的名称.
ProcessGetParent 返回创建指定进程的进程 ID(PID).
ProcessGetPath 返回指定进程的路径.
ProcessSetPriority 更改第一个匹配进程的优先级.
ProcessWait 等待指定的进程存在.
ProcessWaitClose 等待匹配进程关闭.

备注

进程列表: 虽然没有 ProcessList 函数, 但示例 #1示例 #2 演示了如何通过 DllCall 或 COM 检索进程.

Run, WinClose, WinKill, WinWait, WinWaitClose, WinExist, 窗口函数

示例

显示通过 DllCallEnumProcesses 获取的运行进程列表.

MyGui := Gui()
LV := MyGui.Add("ListView", "w1300 r25", ["#", "PID", "Name", "Path"])
for Index, Proc in GetProcessList()
    LV.Add("", Index, Proc.PID, Proc.Name, Proc.Path)
LV.ModifyCol()
MyGui.Title := LV.GetCount() " Processes"
MyGui.Show()

GetProcessList(MaxProcs := 1024) {
    Arr := []  ; 用于存储进程信息的数组
    DllCall("Psapi.dll\EnumProcesses"
        , "Ptr", Buf := Buffer(MaxProcs * 4)  ; 用于存储所有进程 ID 的缓冲
        , "UInt", Buf.Size
        , "UIntP", &ByteCnt := 0)  ; DllCall 返回的字节数
    Loop (ByteCnt // 4) {
        PID := NumGet(Buf, (A_Index - 1) * 4, "UInt")
        try Arr.Push({
            Name: ProcessGetName(PID),
            Path: ProcessGetPath(PID),
            PID: PID
        })
    }
    return Arr
}

显示使用 COM 和 Win32_Process 获取的正在运行的进程列表.

MyGui := Gui(, "Process List")
LV := MyGui.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)
MyGui.Show()