- 按键认证大神
- 8648672
- 35
- 11
- 573 朵
- 299 个
- 159 个
- 0
- 2022-03-06
|
1#
t
T
发表于 2022-05-07 11:22
|
|只看楼主
按键X提供了让人惊叹的扩展能力,除了按键2014就支持的COM插件外,还支持Lua插件、Win32SDK API 插件、C语言的 Lua mod 插件。 按键X最初发布的时候,我和神梦、山海师等人设计开发了按键星月扩展库: http://bbs.anjian.com/showtopic-664233-1.aspx这里展示一下这个扩展库的能力,主要是进程处理部分,也展示一下按键X的扩展调用能力。 先上图最终成品效果图:接下来解析源代码:要使用xyAPI扩展库,需要先将 xyapi.dll 放入脚本的附件目录内,然后在脚本里声明相应的功能,这里只声明进程相关的功能: - // 进程库
- Declare Function Process_Is64 Lib "xyapi.dll" (ByVal pHdr As Long) As Long
- Declare Function PID_Is64 Lib "xyapi.dll" (ByVal pid As Long) As Long
- Declare Function Process_CmdLine Lib "xyapi.dll" (ByVal pHdr As Long) As String
- Declare Function PID_CmdLine Lib "xyapi.dll" (ByVal pid As Long) As String
- Declare Function Process_CurPath Lib "xyapi.dll" (ByVal pHdr As Long) As String
- Declare Function PID_CurPath Lib "xyapi.dll" (ByVal pid As Long) As String
- Declare Function Process_GetPath Lib "xyapi.dll" (ByVal pHdr As Long) As String
- Declare Function PID_GetPath Lib "xyapi.dll" (ByVal pid As Long) As String
- Declare Function Process_Parent Lib "xyapi.dll" (ByVal pHdr As Long) As Long
- Declare Function PID_Parent Lib "xyapi.dll" (ByVal pid As Long) As Long
- Declare Function Process_H2ID Lib "xyapi.dll" (ByVal pHdr As Long) As Long
- Declare Function Process_List Lib "xyapi.dll" () As String
- Declare Function Process_FindChild Lib "xyapi.dll" (ByVal pHdr As Long) As Long
- Declare Function PID_FindChild Lib "xyapi.dll" (ByVal pid As Long) As Long
- Declare Function Process_ListChild Lib "xyapi.dll" (ByVal pHdr As Long) As String
- Declare Function PID_ListChild Lib "xyapi.dll" (ByVal pid As Long) As String
- Declare Function Process_Status Lib "xyapi.dll" (ByVal pHdr As Long) As Long
- Declare Function PID_Status Lib "xyapi.dll" (ByVal pid As Long) As Long
- Declare Function Process_Kill Lib "xyapi.dll" (ByVal pHdr As Long) As Long
- Declare Function PID_Kill Lib "xyapi.dll" (ByVal pid As Long) As Long
复制代码声明完成后,这些功能就都可以使用了,PID_ 开头的命令使用进程PID来控制进程,Process_ 开头的命令则使用进程句柄控制进程。 之后,在窗口加载时,我们需要将进程列表显示出来,我们先实现进程列表刷新的功能,然后在窗口加载时调用这个功能即可: - // 窗口加载
- Event Form1.Load
- Form1.Button1.Click()
- End Event
- // 刷新列表
- Event Form1.Button1.Click
- Dim PList = Split(Process_List(), "\r\n")
- Form1.Grid1.RowCount = UBound(PList) + 1
- For i = 1 To UBound(PList)
- Dim PInfo = Split(PList(i), "|")
- Form1.Grid1.SetItemText(i, 0, PInfo(1))
- Form1.Grid1.SetItemText(i, 1, PInfo(2))
- Form1.Grid1.SetItemText(i, 2, iif(PID_Is64(CLng(PInfo(2))) = 0, "32位", "64位"))
- Form1.Grid1.SetItemText(i, 3, PInfo(3))
- Form1.Grid1.SetItemText(i, 4, PInfo(4))
- Form1.Grid1.SetItemText(i, 5, CStr(PID_Parent(CLng(PInfo(2)))))
- Next
- End Event
复制代码进程列表使用 Process_List 命令获取,他会返回使用 \r\n 分割的进程列表信息,每行一个进程,进程内的信息则用 | 分割。 将信息分割后,我们就可以把进程列表展示出来了。 进程信息里面保存着进程PID,也就是说我们拿到这个列表之后,就可以控制这个列表的进程了,比如获取更详细的信息,或者结束进程、定位文件等。 下面是获取进程信息的代码: - // 进程信息
- Event Form1.Button4.Click
- Dim LineE, PID
- PID, PID, LineE, PID = Form1.Grid1.GetSelectedRange()
- PID = CLng(Form1.Grid1.GetItemText(LineE, 1))
- Dim PInfo = "进程信息\r\n\r\n映像名:\t" & Form1.Grid1.GetItemText(LineE, 0)
- PInfo = PInfo & "\r\n进程PID:\t" & PID
- PInfo = PInfo & "\r\n父进程PID:\t" & PID_Parent(PID)
- PInfo = PInfo & "\r\n进程位数:\t" & iif(PID_Is64(PID) = 0, "32位", "64位")
- PInfo = PInfo & "\r\n进程优先级:\t" & Form1.Grid1.GetItemText(LineE, 3)
- PInfo = PInfo & "\r\n线程数量:\t" & Form1.Grid1.GetItemText(LineE, 4)
- PInfo = PInfo & "\r\n进程启动命令行:" & PID_CmdLine(PID)
- PInfo = PInfo & "\r\n进程工作目录:\t" & PID_CurPath(PID)
- PInfo = PInfo & "\r\n进程文件路径:\t" & PID_GetPath(PID)
- PInfo = PInfo & "\r\n进程状态:\t" & iif(PID_Status(PID) = 0, "已结束", "正在运行")
- PInfo = PInfo & "\r\n\r\n子进程列表:\r\n\r\n映像名\t\tPID\t优先级\t线程数量\r\n\r\n" & Replace(PID_ListChild(PID), "|", "\t")
- MsgBox PInfo
- End Event
复制代码xyAPI 支持获取的进程信息还是比较多的,其中很多信息是从 PBI 表里面拿出来的,和系统任务管理器的原理一样,同时支持64位进程和32位进程。 进程信息里可以获取到文件路径,所以我们也可以定位到文件的位置: - // 定位文件
- Event Form1.Button5.Click
- Dim LineE, PID
- PID, PID, LineE, PID = Form1.Grid1.GetSelectedRange()
- PID = CLng(Form1.Grid1.GetItemText(LineE, 1))
- RunApp "explorer /n,/select," & PID_GetPath(PID)
- End Event
- // 定位工作目录
- Event Form1.Button6.Click
- Dim LineE, PID
- PID, PID, LineE, PID = Form1.Grid1.GetSelectedRange()
- PID = CLng(Form1.Grid1.GetItemText(LineE, 1))
- RunApp "explorer /n,/root," & PID_CurPath(PID)
- End Event
复制代码当然也可以结束进程或者结束进程树: - // 结束进程树
- Event Form1.Button3.Click
- Dim LineE, PID
- PID, PID, LineE, PID = Form1.Grid1.GetSelectedRange()
- PID = CLng(Form1.Grid1.GetItemText(LineE, 1))
- Dim PList = Split(PID_ListChild(PID), "\r\n")
- For i = 1 To UBound(PList)
- Dim PInfo = Split(PList(i), "|")
- PID_Kill(CLng(PInfo(2)))
- Next
- PID_Kill(PID)
- MsgBox "进程结束完毕"
- End Event
- // 结束进程
- Event Form1.Button2.Click
- Dim LineE, PID
- PID, PID, LineE, PID = Form1.Grid1.GetSelectedRange()
- PID = CLng(Form1.Grid1.GetItemText(LineE, 1))
- PID_Kill(PID)
- MsgBox "进程结束完毕"
- End Event
复制代码结束进程树功能使用 PID_ListChild 遍历子进程,然后结束所有子进程,对于脚本开发来说,这个功能也是很有用的,比如运行起来一个程序之后,这个程序还会打开其他乱七八糟的东西,直接结束掉这个进程,它的子进程就残留住了,可以遍历一下,然后全部杀掉! 最终制作完成的小精灵下载: - PM.zip (, 下载次数:213)
按键精灵X版任务管理器源代码下载:- PMsrc.zip (, 下载次数:160)
|