Nevi Posted September 25, 2014 Posted September 25, 2014 Could anyone show me what's wrong here? Func _getPID($ProcessName) Local $i = 0 Local $PID = 0 While ( $i + 1 <= ProcessList($ProcessName)[0][0] ) $PID[$i] = ProcessList($ProcessName)[$i+1][1] ; probably this one. $i = $i + 1 WEnd Return ($PID) EndFunc _getPID("explorer.exe") Thank you.
MikahS Posted September 25, 2014 Posted September 25, 2014 (edited) Why not just use ProcessList('explorer.exe') ? EDIT: If you have the error please post it, I bet it is has to do with the fact that your trying to use a regular variable as an array like so $PID[$i] Edited September 25, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
MikahS Posted September 25, 2014 Posted September 25, 2014 (edited) ProcessList - Returns an array listing the currently running processes (names and PIDs). Edited September 25, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
Nevi Posted September 25, 2014 Author Posted September 25, 2014 (edited) ProcessList - Returns an array listing the currently running processes (names and PIDs). Thanks. However, how do you list the PID of multiple processes with the same name? I'm a bit confused, now. PS: The error is in the title. Sorry for the confusion. Edited September 25, 2014 by Nevi
MikahS Posted September 25, 2014 Posted September 25, 2014 (edited) Return Value Success: an array of process names and PIDs (See Remarks). Failure: sets the @error flag to 1 when the array cannot be built. Remarks The array returned is two-dimensional and is made up as follows: $aArray[0][0] = Number of processes $aArray[1][0] = 1st Process name $aArray[1][1] = 1st Process ID (PID) $aArray[2][0] = 2nd Process name $aArray[2][1] = 2nd Process ID (PID) ... $aArray[n][0] = nth Process name $aArray[n][1] = nth Process ID (PID) The list can be empty if $aArray[0][0] = 0. No @error set in this case. The helpfile is your friend If that wasn't clear it will list all running names and PIDs of the process. Edited September 25, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
Moderators Solution JLogan3o13 Posted September 25, 2014 Moderators Solution Posted September 25, 2014 (edited) You initalize $PID to 0, then call the function passing the ProcessName, but never do anything more with $PID. Why wouldn't you get an error? Try this to see why it is failing: Func _getPID($ProcessName) Local $i = 0 Local $PID = 0 While ( $i + 1 <= ProcessList($ProcessName)[0][0] ) If Not IsArray($PID) Then MsgBox(0, "", "$PID is NOT an array so $PID[$i] will FAIL. $PID = " & $PID) Exit EndIf $PID[$i] = ProcessList($ProcessName)[$i+1][1] ; probably this one. $i = $i + 1 WEnd Return ($PID) EndFunc _getPID("explorer.exe") Edited September 25, 2014 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
MikahS Posted September 25, 2014 Posted September 25, 2014 (edited) You initalize $PID to 0, then call the function passing the ProcessName, but never do anything more with $PID. Why wouldn't you get an error? Try this to see why it is failing: Func _getPID($ProcessName) Local $i = 0 Local $PID = 0 While ( $i + 1 <= ProcessList($ProcessName)[0][0] ) If Not IsArray($PID) Then MsgBox(0, "", "$PID is NOT an array so $PID[$i] will FAIL. $PID = " & $PID) Exit EndIf $PID[$i] = ProcessList($ProcessName)[$i+1][1] ; probably this one. $i = $i + 1 WEnd Return ($PID) EndFunc _getPID("explorer.exe") This will fail everytime. obviously it will, but isn't doing this much work a little redundant or am I just being dumb? Edited September 25, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
Moderators JLogan3o13 Posted September 25, 2014 Moderators Posted September 25, 2014 Precisely the point I am trying to make - the OP is asking why his code is failing. That demonstrates why. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Nevi Posted September 25, 2014 Author Posted September 25, 2014 Precisely the point I am trying to make - the OP is asking why his code is failing. That demonstrates why. Thank you very very much!
MikahS Posted September 25, 2014 Posted September 25, 2014 EDIT: If you have the error please post it, I bet it is has to do with the fact that your trying to use a regular variable as an array like so $PID[$i] Precisely the point I am trying to make - the OP is asking why his code is failing. That demonstrates why. Ah, I see they just skipped over Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
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