ripdad Posted April 29, 2011 Share Posted April 29, 2011 A little something I made to be able to cross-reference processes, PID's and full paths. One could obtain alot of info if manipulated properly with some extra code. (might be a little sluggish on some systems obtaining running processes) Thanks goes to SumTingWong for his function _ServiceRunning() expandcollapse popup; ProcessList_Extended ; Date Released: April 29, 2011 ; Example: Yes ; #include <array.au3> If _ServiceRunning('winmgmt') <> 1 Then MsgBox(8208, 'Error', 'WMI Service Not Available') Exit EndIf ; 3 Examples ==> $ple = ProcessList_Extended(1, 1) _ArrayDisplay($ple, 'Example 1 - Filtered Process List with Full Paths') ; $ple = ProcessList_Extended(0, 0) _ArrayDisplay($ple, 'Example 2 - Process by PID') ; $ple = ProcessList_Extended(0, 1) _ArrayDisplay($ple, 'Example 3 - Process by Occurrence') ; <== Func ProcessList_Extended($filter = 0, $sort = 0) Local $objWMI, $colItems, $PATH, $PID, $c = 0 $objWMI = ObjGet('Winmgmts:{ImpersonationLevel=Impersonate,AuthenticationLevel=PktPrivacy,(Debug)}!\\.\root\cimv2') $colItems = $objWMI.ExecQuery('Select * From CIM_ProcessExecutable', 'WQL', 0x30) If Not IsObj($colItems) Then Return SetError(-1) Local $array[1][2] For $oItem In $colItems $PATH = StringRegExp($oItem.Antecedent, '(?i)"(.*?)"', 3) $PID = StringRegExp($oItem.Dependent, '(?i)"(.*?)"', 3) ; If $filter Then If StringRegExp(StringRight($PATH[0], 3), '(?i)cmd|com|exe|msi|scr') <> 1 Then ContinueLoop EndIf $c += 1 ReDim $array[$c + 1][2] $array[$c][0] = StringReplace($PATH[0], '\\', '\') $array[$c][1] = $PID[0] ; Next If $sort Then _ArraySort($array, 0, 1) $array[0][0] = UBound($array) - 1 $array[0][1] = 'PID' Return SetError(0, 0, $array) EndFunc ; ;=============================================================================== ; ; Description: Checks to see if a service is running ; Syntax: _ServiceRunning($sServiceName) ; Parameter(s): $sServiceName - Name of service to check ; Requirement(s): None ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; Author(s): SumTingWong ; Documented by: noone ; ;=============================================================================== Func _ServiceRunning($sServiceName, $sComputer = "") Local $arRet, $hSC, $hService, $bRunning = 0 $arRet = DllCall("advapi32.dll", "long", "OpenSCManager", "str", $sComputer, "str", "ServicesActive", "long", 0x0001) If $arRet[0] <> 0 Then $hSC = $arRet[0] $arRet = DllCall("advapi32.dll", "long", "OpenService", "long", $hSC, "str", $sServiceName, "long", 0x0080) If $arRet[0] <> 0 Then $hService = $arRet[0] $arRet = DllCall("advapi32.dll", "int", "ControlService", "long", $hService, "long", 0x00000004, "str", "") $bRunning = $arRet[0] DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService) EndIf DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC) EndIf Return $bRunning EndFunc ; "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
wakillon Posted April 30, 2011 Share Posted April 30, 2011 I did not doubt that there were many processes at the same time...Very interesting ! Thanks. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
ripdad Posted April 30, 2011 Author Share Posted April 30, 2011 You're welcome. BTW, I forgot to mention .. "Run As Admin" on Win_Vista and Win_7 to get more processes. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now