;===============================================================================
; Function Name: _ProcessListProperties()
; Description: Get various properties of a process, or all processes
; Call With: _ProcessListProperties( [$Process [, $sComputer]] )
; Parameter(s): (optional) $Process - PID or name of a process, default is "" (all)
; (optional) $sComputer - remote computer to get list from, default is local
; Requirement(s): AutoIt v3.2.4.9+
; Return Value(s): On Success - Returns a 2D array of processes, as in ProcessList()
; with additional columns added:
; [0][0] - Number of processes listed (can be 0 if no matches found)
; [1][0] - 1st process name
; [1][1] - 1st process PID
; [1][2] - 1st process Parent PID
; [1][3] - 1st process owner
; [1][4] - 1st process priority (0 = low, 31 = high)
; [1][5] - 1st process executable path
; [1][6] - 1st process CPU usage
; [1][7] - 1st process memory usage
; [1][8] - 1st process creation date/time = "MM/DD/YYY hh:mm:ss" (hh = 00 to 23)
; [1][9] - 1st process command line string
; ...
; [n][0] thru [n][9] - last process properties
; On Failure: Returns array with [0][0] = 0 and sets @Error to non-zero (see code below)
; Author(s): PsaltyDS at http://www.autoitscript.com/forum
; Date/Version: 07/02/2008 -- v2.0.2
; Notes: If an integer PID or string process name is provided and no match is found,
; then [0][0] = 0 and @error = 0 (not treated as an error, same as ProcessList)
; This function requires admin permissions to the target computer.
; All properties come from the Win32_Process class in WMI.
; To get time-base properties (CPU and Memory usage), a 100ms SWbemRefresher is used.
;===============================================================================
Func _ProcessListProperties($Process = "", $sComputer = ".")
Local $sUserName, $sMsg, $sUserDomain, $avProcs, $dtmDate
Local $avProcs[1][2] = [[0, ""]], $n = 1
; Convert PID if passed as string
If StringIsInt($Process) Then $Process = Int($Process)
; Connect to WMI and get process objects
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" & $sComputer & "\root\cimv2")
If IsObj($oWMI) Then
; Get collection processes from Win32_Process
If $Process = "" Then
; Get all
$colProcs = $oWMI.ExecQuery("select * from win32_process")
ElseIf IsInt($Process) Then
; Get by PID
$colProcs = $oWMI.ExecQuery("select * from win32_process where ProcessId = " & $Process)
Else
; Get by Name
$colProcs = $oWMI.ExecQuery("select * from win32_process where Name = '" & $Process & "'")
EndIf
If IsObj($colProcs) Then
; Return for no matches
If $colProcs.count = 0 Then Return $avProcs
; Size the array
ReDim $avProcs[$colProcs.count + 1][10]
$avProcs[0][0] = UBound($avProcs) - 1
; For each process...
For $oProc In $colProcs
; [n][0] = Process name
$avProcs[$n][0] = $oProc.name
; [n][1] = Process PID
$avProcs[$n][1] = $oProc.ProcessId
; [n][2] = Parent PID
$avProcs[$n][2] = $oProc.ParentProcessId
; [n][3] = Owner
If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n][3] = $sUserDomain & "\" & $sUserName
; [n][4] = Priority
$avProcs[$n][4] = $oProc.Priority
; [n][5] = Executable path
$avProcs[$n][5] = $oProc.ExecutablePath
; [n][8] = Creation date/time
$dtmDate = $oProc.CreationDate
If $dtmDate <> "" Then
; Back referencing RegExp pattern from weaponx
Local $sRegExpPatt = "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)"
$dtmDate = StringRegExpReplace($dtmDate, $sRegExpPatt, "$2/$3/$1 $4:$5:$6")
EndIf
$avProcs[$n][8] = $dtmDate
; [n][9] = Command line string
$avProcs[$n][9] = $oProc.CommandLine
; increment index
$n += 1
Next
Else
SetError(2); Error getting process collection from WMI
EndIf
; release the collection object
$colProcs = 0
; Get collection of all processes from Win32_PerfFormattedData_PerfProc_Process
; Have to use an SWbemRefresher to pull the collection, or all Perf data will be zeros
Local $oRefresher = ObjCreate("WbemScripting.SWbemRefresher")
$colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet
$oRefresher.Refresh
; Time delay before calling refresher
Local $iTime = TimerInit()
Do
Sleep(20)
Until TimerDiff($iTime) >= 100
$oRefresher.Refresh
; Get PerfProc data
For $oProc In $colProcs
; Find it in the array
For $n = 1 To $avProcs[0][0]
If $avProcs[$n][1] = $oProc.IDProcess Then
; [n][6] = CPU usage
$avProcs[$n][6] = $oProc.PercentProcessorTime
; [n][7] = memory usage
$avProcs[$n][7] = $oProc.WorkingSet
ExitLoop
EndIf
Next
Next
Else
SetError(1); Error connecting to WMI
EndIf
; Return array
Return $avProcs
EndFunc;==>_ProcessListProperties
$avRET = _ProcessListProperties("notepad.exe")
MsgBox(0,"Memory Usage",$avRET[1][7])
分享到:
相关推荐
scite4AutoIT3,只有这个版本的AutoIT才可以添加版本信息、版权信息、还有程序图标等,只AutoIT3,即可加了以下代码,也是没有办法编译带有exe版本,版权,公司等信息的,这个版本还有一些额外的工具,获取按钮位置等...
AutoIt的Script语法类似于VBScript,简单易学。 AutoIt 3是此类软件中影响最大的经典产品。现在能与它一争高低的只有AutoHotkey(为AutoIt成员另立门户之产品,参见AutoIT3 vs AutoHotkey)。 或者是为了...
autoit3 信息管理例子
autoit控制chrome的扩展库,正式拜托麻烦的IE
AutoIt教程 AutoIt教程 AutoIt教程 AutoIt教程 AutoIt教程
1. 安装 AutoIt 3.8.8.02. 开启檔案并且 Ctrl+F7 编译后,放置 USB 内3. 将USB插入其它计算机中,点击启动程序,当中途拔出USB (未关闭程序情况下),屏幕将呈现黑屏锁机,再次插入USB后,即可恢复屏幕
autoit关于excel的操作
AutoIT
获取U盘设备的基础信息,如磁盘号、序列号,资源来自 Autoit中文网
直接与窗口的“控件“交互(设置/获取 文字、移动、关闭, 等等) 配合剪贴板进行剪切/粘贴文本操作 对注册表进行操作 不同于 AutoIt v2,新的v3版本含有更多的标准语法——类似 于VBScript和BASIC——而且现在...
autoit轻松入门系列 autoit轻松入门系列
Autoit的中文帮助手册,AutoIt v3 是一个类似 BASIC 脚本语言的免费软件, 设计用于在 Windows GUI(图形用户界面) 中进行自动化操作. 利用模拟键盘按键, 鼠标移动和窗口/控件的操作实现自动化任务. 而这是其它语言不...
autoit 的安装文档
直接与窗口的"标准控件"交互(设置/获取 文字,移动,关闭,等等) 脚本可以编译为标准可执行文件 创建用户图形界面接口(GUI) COM支持 正则表达式 直接调用外部DLL 和 Windows API 函数 程序运行为功能(让程序运行于其它...
AutoIt 3是一款功能强大的脚本(Script)工具,它提供了一个执行Script的平台,并且,它可以把它...直接与窗口的“控件“交互(设置/获取 文字、移动、关闭,等等) 配合剪贴板进行剪切/粘贴文本操作 对注册表进行操作
autoit 获取按下的键盘字母,同时可以根据相应的字母做其他处理动作,同时可以根据相应的字母做其他处理动作,同时可以根据相应的字母做其他处理动作,同时可以根据相应的字母做其他处理动作
autoit3常用的函数,方便查找,需要的可以下在
autoit 解决二维数组动态赋值
autoit 读取xml代码
AutoIt多线程的标准教程 AutoIt多线程的标准教程