excelsi Posted September 30, 2015 Posted September 30, 2015 (edited) Hi,i think its very simple to solve this problem but i cannot see where it is...Here is the code:expandcollapse popup#include <array.au3> ;$iPid = Run("cleanmgr.exe") ;Sleep(10) ; allow notepad to create window $aArray = _WinGetInfoByProcess("cleanmgr.exe", 1) ;If not $aArray[1][0] = "" Then ( If IsArray($aArray[1][0]) Then ( $WName = $aArray[1][0] ; Wait 0 seconds for the Cleanmgr window to appear. Local $hWnd = WinWait($WName, "", 0) ; Set the state of the Cleanmgr window to "hide". WinSetState($hWnd, "", @SW_HIDE) ) ;MsgBox(0,"Value","The Value is" & $iIndex) ;_ArrayDisplay($aArray, "by Name, only visible windows") Func _WinGetInfoByProcess($vProcess = "cleanmgr.exe", $nShow = 2) ; ;=============================================================================== ; ; Function Name: _WinGetInfoByProcess ; Description:: Get Window Handle of Process ; Parameter(s): $vProcess = Processname(e.g. "Notepad.exe") or Processnumber(e.g. 4711 ) ; $nShow = -1 "All (Visble or not)" ; $nShow = 0 "Not Visible Only" ; $nShow = 1 "Visible Only" ; $nShow = 2 "Return handle of newest window " (Default) ; Requirement(s): none ; Return Value(s): ; @extended = returns number of entries in the array ; @error = 0 AND $nShow = 2 (default) returns handle of newest window ; @error = 0 returns array with processinfos ; n = 1 to @extended ; Array[n][0] shows windows title. ; Array[n][1] shows windows handle. ; Array[n][2] shows windows Pid. ; @error = 1 Process not found. ; @error = 2 Window not found. ; Author(s): inspired by Smoke_N's script _WinGetHandleByPID() ; but to handle more than one process with the same name ; and to return handle of newest window ($nShow = 2). ; tested versions: Autoit 3.3.0.0 ; ;=============================================================================== ; If Not ProcessExists($vProcess) Then Return SetError(1, 0, 0) ; no matching process Local $iWinList, $aWinList = WinList() Local $iResult, $aResult[UBound($aWinList)][3] Local $iProcessList, $aProcessList = ProcessList($vProcess) If $aProcessList[0][0] = 0 Then Local $aProcessList[2][2] = [[1, 0],["", $vProcess]] For $iWinList = 1 To $aWinList[0][0] For $iProcessList = 1 To $aProcessList[0][0] If WinGetProcess($aWinList[$iWinList][1]) = $aProcessList[$iProcessList][1] Then If $nShow > -1 And Not $nShow = (2 = BitAND(WinGetState($aWinList[$iWinList][1]), 2)) Then ContinueLoop $iResult += 1 $aResult[$iResult][0] = $aWinList[$iWinList][0] $aResult[$iResult][1] = $aWinList[$iWinList][1] $aResult[$iResult][2] = $aProcessList[$iProcessList][1] EndIf Next Next If $iResult = 0 Then Return SetError(2, 0, 0) ; no window found ReDim $aResult[$iResult + 1][3] $aResult[0][0] = $iResult If $nShow = 2 Then Return SetError(0, $iResult, $aResult[1][1]) Return SetError(0, $iResult, $aResult) EndFunc ;==>_WinGetInfoByProcess_________________________________________________________________________________________________________________________________The Function works as expected, only this part is the problem:If IsArray($aArray[1][0]) Then ( $WName = $aArray[1][0] ; Wait 0 seconds for the Cleanmgr window to appear. Local $hWnd = WinWait($WName, "", 0) ; Set the state of the Cleanmgr window to "hide". WinSetState($hWnd, "", @SW_HIDE) )If the array value exists he should execute the following commands, if not he should simply exit without error message.At them moment i get first: Unbalanced brackets in expressionAnd if the Array value doesn't exist: Subscript used on non accessible variable (This error i want to workarround with the If Statement)Thanks for your help.Michael Edited September 30, 2015 by Melba23 Added code tags
Moderators Melba23 Posted September 30, 2015 Moderators Posted September 30, 2015 excelsi,Welcome to the AutoIt forums.When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.Now to look at the code you posted.....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
Moderators Melba23 Posted September 30, 2015 Moderators Posted September 30, 2015 excelsi,You get the "Unbalanced brackets in expression" error because you have unbalanced brackets - you do not need these ones:If IsArray($aArray[1][0]) Then ( ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $WName = $aArray[1][0] ; Wait 0 seconds for the Cleanmgr window to appear. Local $hWnd = WinWait($WName, "", 0) ; Set the state of the Cleanmgr window to "hide". WinSetState($hWnd, "", @SW_HIDE) ) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<But I would approach the whole thing slightly differently:#include <MsgBoxConstants.au3> $iPid = Run("cleanmgr.exe") ; Look for max 10 sec $nBegin = TimerInit() While 1 ; See if a window has appeared - using $nShow = 1 returns an array if the window exists and an error if not $aArray = _WinGetInfoByProcess("cleanmgr.exe", 1) ; No error, so window has appeared and we continue If @error = 0 Then ExitLoop ; Check timeout has not expired If TimerDiff($nBegin) > 10 * 1000 Then ; Announce failure and exit MsgBox($MB_SYSTEMMODAL, "Error", "Timeout") Exit EndIf ; Try again Wend ; We have found a window, so extract name ; But it would be better to use handle $WName = $aArray[1][0] ; $hWnd = $aArray[1][1] WinSetState($WName, "", @SW_HIDE) ; WinSetState($hWnd, "", @SW_HIDE) Func _WinGetInfoByProcess($vProcess, $nShow = 2) ; Do not force CleanMgr name here ; Rest of codeThat works for me - please ask if you have any questions.M23 Skysnake 1 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
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