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