Jump to content
Sign in to follow this  
/\/\1|<3

Process Functions

Recommended Posts

i coded these functions because i was very bored :">

maybe its usefull for a few of you

the first function returns an array conating the number of processes found (array[0]) and the others contain the Ids of the processes by giving the name of the process

the second function returns the name of a process by giving its Id

Func ProcessGetId($Process)
    If IsString($Process) = 0 Then
        SetError(2)
    ElseIf ProcessExists($Process) = 0 Then
        SetError(1)
    Else
        
        Local $PList = ProcessList($Process)
        Local $i
        Local $PId[$PList[0][0] + 1]
        
        $PId[0] = $PList[0][0]
        
        For $i = 1 To $PList[0][0]
            $PId[$i] = $PList[$i][1]
        Next
        
        Return $PId
    EndIf
EndFunc

Func ProcessGetName($PId)
    If IsNumber($PId) = 0 Then
        SetError(2)
    ElseIf $PId > 9999 Then
        SetError(1)
    Else
        
        Local $PList = ProcessList()
        Local $i = 1
        Local $ProcessName = ""
        
        While $i <= $PList[0][0] And $ProcessName = ""
            If $PList[$i][1] = $PId Then
                $ProcessName = $PList[$i][0]
            Else
                $i = $i + 1
            EndIf
        WEnd
        
        Return $ProcessName
    EndIf
EndFunc

example:

$PId = ProcessGetId("notepad.exe"); Gets the PId
MsgBox(0, "Processes: " & $PId[0], "First process Id: " & $PId[1]); shows the Id
MsgBox(0, "Name Check", "Given name was: " & ProcessGetName($PId[1])); shows the name

for the following function you need the Id of a Process. you can get it with my ProcessGetId function. you also need my ProcessGetName function:

Func ProcessGetWindow($PId)
    If IsNumber($PId) = 0 Or ProcessExists(ProcessGetName($PId)) = 0 Then
        SetError(1)
    Else
        
        Local $WinList = WinList()
        Local $i = 1
        Local $WindowTitle = ""
        
        While $i <= $WinList[0][0] And $WindowTitle = ""
            If WinGetProcess($WinList[$i][0], "") = $PId Then
                $WindowTitle = $WinList[$i][0]
            Else
                $i = $i + 1
            EndIf
        WEnd
        
        Return $WindowTitle
    EndIf
EndFunc

i hope you like it

Mike

Edited by /\/\1|<3

Share this post


Link to post
Share on other sites

I see a sanity check where you look to see if a PID is less than 1000... A PID can be less than 1000. There are 6 processes on my system with a PID less than 1000, 5 of which are running under my account, the other under SYSTEM. There are two more if you count System and System Idle Process.

Share this post


Link to post
Share on other sites

- added ProcessGetWindow function

if you use it like this:

$PId = ProcessGetId("Diablo II.exe")
For $i = 1 To $PId[0]
    MsgBox(0, "window matching with " & $PId[$i], ProcessGetWindow($PId[$i]))
Next

then it shows you all existing diablo 2 windows

enjoy :lmao:

Mike

Share this post


Link to post
Share on other sites

Awesome :lmao:


"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...