Caiol Posted February 11, 2011 Share Posted February 11, 2011 Hello everyone... I'm getting an error with my script: "Subscript used with non-Array variable" Script: While ProcessExists("msskn.exe") $iPID = ProcessExists("msskn.exe") $get = _ProcessGetLoadedModules($iPID) $max = UBound($get) if $max-1 > $i Then $i = $i + 1 Elseif $i = $max-1 Then $i = 0 ElseIf $i > $max-1 Then $i = 0 Else $i = 0 EndIf $TestPath = _PathSplit($get[$i], $szDrive, $szDir, $szFName, $szExt) WEnd I don't know what is the problem... i'd tryed everything that I known... Function _ProcessGetLoadedModules: expandcollapse popup#Include <WinAPI.au3> ; #FUNCTION#;=============================================================================== ; ; Name...........: _ProcessGetLoadedModules ; Description ...: Returns an array containing the full path of the loaded modules ; Syntax.........: _ProcessGetLoadedModules($iPID) ; Parameters ....: ; Return values .: Success - An array with all the paths ; : Failure - -1 and @error=1 if the specified process couldn't be opened. ; Author ........: Andreas Karlsson (monoceres) & ProgAndy ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; No ; ;;========================================================================================== Func _ProcessGetLoadedModules($iPID) Local Const $PROCESS_QUERY_INFORMATION=0x0400 Local Const $PROCESS_VM_READ=0x0010 Local $aCall, $hPsapi=DllOpen("Psapi.dll") Local $hProcess, $tModulesStruct $tModulesStruct=DllStructCreate("hwnd [200]") Local $SIZEOFHWND = DllStructGetSize($tModulesStruct)/200 $hProcess=_WinAPI_OpenProcess(BitOR($PROCESS_QUERY_INFORMATION,$PROCESS_VM_READ),False,$iPID) If Not $hProcess Then Return SetError(1,0,-1) $aCall=DllCall($hPsapi,"int","EnumProcessModules","ptr",$hProcess,"ptr",DllStructGetPtr($tModulesStruct),"dword",DllStructGetSize($tModulesStruct),"dword*","") If $aCall[4]>DllStructGetSize($tModulesStruct) Then $Dimensions = $aCall[4] / $SIZEOFHWND If $Dimensions <= 0 Then $Dimensions = 1 ;just an example $tModulesStruct=DllStructCreate("hwnd ["&$dimensions&"]") $aCall=DllCall($hPsapi,"int","EnumProcessModules","ptr",$hProcess,"ptr",DllStructGetPtr($tModulesStruct),"dword",$aCall[4],"dword*","") EndIf $Dimensions = $aCall[4] / $SIZEOFHWND If $Dimensions <= 0 Then $Dimensions = 1 ;just an example Local $aReturn[$Dimensions] ;This way, you will not get an error For $i=0 To Ubound($aReturn)-1 $aCall=DllCall($hPsapi,"dword","GetModuleFileNameExW","ptr",$hProcess,"ptr",DllStructGetData($tModulesStruct,1,$i+1),"wstr","","dword",65536) $aReturn[$i]=$aCall[3] Next _WinAPI_CloseHandle($hProcess) DllClose($hPsapi) Return $aReturn EndFunc Someone helps? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 11, 2011 Moderators Share Posted February 11, 2011 Caiol,Looking at the header for _ProcessGetLoadedModules you see the following:; Return values .: Success - An array with all the paths ; : Failure - -1 and @error=1 if the specified process couldn't be opened.So I would suggest that the function is failing to return an array and then you get the error when you try to read the array elements. What you need to do is to add an errorchecking line to check for @error after the function return and only run the rest of your code if it is not set. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Caiol Posted February 11, 2011 Author Share Posted February 11, 2011 Thanks Melba23, i think it's correct... I didn't think in this possibility... Very good... The error was only appearing at the end of the script... just where the process exits and the function return failure... 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