Jump to content

Recommended Posts

Posted (edited)

Hello,

I am trying to see if a new process started which works most of the time. But sometimes there is an error "Array variable has incorrect number of subscripts or subscript dimension range exceeded."

I suspect a new process started and caused an issue here but I am not sure (am I using autoit arrays incorrectly?). Anyone see an issue with this?

CODE
; check to see if list of running processes are different

Func TestForChangedProcesses()

$currentProcesses=ProcessList()

For $i=1 To $currentProcesses[0][0]-1

If Not($currentProcesses[$i][0] == $list[$i][0]) Then ; check to see if saved processes are different

LogToFile("Application changed " & $currentProcesses[$i][0])

$list=$currentProcesses ; because processes changed set new list to be the one to test against

EndIf

next

EndFunc

Edited by maestro1024
Posted

Hello,

I am trying to see if a new process started which works most of the time. But sometimes there is an error "Array variable has incorrect number of subscripts or subscript dimension range exceeded."

I suspect a new process started and caused an issue here but I am not sure (am I using autoit arrays incorrectly?). Anyone see an issue with this?

CODE
; check to see if list of running processes are different

Func TestForChangedProcesses()

$currentProcesses=ProcessList()

For $i=1 To $currentProcesses[0][0]-1

If Not($currentProcesses[$i][0] == $list[$i][0]) Then ; check to see if saved processes are different

LogToFile("Application changed " & $currentProcesses[$i][0])

$list=$currentProcesses ; because processes changed set new list to be the one to test against

EndIf

next

EndFunc

Which line is the error happening on?

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Posted

Thanks

But I am not sure I see the difference. Where in this code are you checking or how do you know you are not out of bounds?

CODE
;Store current processlist "state"

$ListOne = ProcessList ()

While 1

$ListTwo = ProcessList ()

;Verify each process exists in original state, if not, KILL IT!!!!!!!!!!!!!!!!

For $X = 1 to $ListTwo[0][0]

$found = false

;Comparing by PID, because danwilli would prefer it

For $Y = 1 to $ListOne[0][0]

If $ListOne[$Y][1] = $ListTwo[$X][1] Then

$found = true

ExitLoop

EndIf

Next

If $found = false Then

MsgBox(0,"","New process found: " & $ListTwo[$X][0])

someFunction()

EndIf

Next

;Check every 3 seconds

Sleep (3000)

WEnd

Func someFunction()

MsgBox(0,"","A new process was opened")

EndFunc

Posted

In your code you are comparing every element like this:

For $i=1 To $currentProcesses[0][0]-1

If Not($currentProcesses[$i][0] == $list[$i][0])

This assumes both arrays have the same number of elements.

My script loops through all elements in the second snapshot one at a time.

For $X = 1 to $ListTwo[0][0]

Then for each of those elements I search every element in the first array:

For $Y = 1 to $ListOne[0][0]

This means the sizes are independent of each other.

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
  • Recently Browsing   0 members

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