/\/\1|<3 Posted January 29, 2005 Share Posted January 29, 2005 (edited) 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 expandcollapse popupFunc 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 February 6, 2005 by /\/\1|<3 Link to comment Share on other sites More sharing options...
Valik Posted January 29, 2005 Share Posted January 29, 2005 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. Link to comment Share on other sites More sharing options...
/\/\1|<3 Posted January 29, 2005 Author Share Posted January 29, 2005 thanks + edited Mike Link to comment Share on other sites More sharing options...
/\/\1|<3 Posted February 6, 2005 Author Share Posted February 6, 2005 - 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 Mike Link to comment Share on other sites More sharing options...
Insolence Posted February 6, 2005 Share Posted February 6, 2005 Awesome "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. Link to comment Share on other sites More sharing options...
bshoenhair Posted February 7, 2005 Share Posted February 7, 2005 @/\/\1|<3 Nice job. 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