Sign in to follow this  
Followers 0
ripdad

ProcessList_Extended

3 posts in this topic

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()

; 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

Share this post


Link to post
Share on other sites



I did not doubt that there were many processes at the same time...Very interesting ! Posted Image

Thanks.


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0