Jump to content

ProcessList | Error : Subscript used on non-accessible variable.


Nevi
 Share

Go to solution Solved by JLogan3o13,

Recommended Posts

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.

Link to comment
Share on other sites

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 by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

 

Link to comment
Share on other sites

ProcessList -

Returns an array listing the currently running processes (names and PIDs).

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

 

Link to comment
Share on other sites

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 by Nevi
Link to comment
Share on other sites

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 by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

 

Link to comment
Share on other sites

  • Moderators
  • Solution

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 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!

Link to comment
Share on other sites

 

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 by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

 

Link to comment
Share on other sites

  • Moderators

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!

Link to comment
Share on other sites

 

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 ~ getENVvars
My 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...