AutoIT Script

Trying to automate ccleaner via autoit v3.xxxx.whatever.

CCleaner is driving me crazy!! Every time I try to fix this script it seems like it chameleons on me and changes so that the script keystrokes don't work.

I already looked on autoit's site/Help Forums with very little success.

Specifically:

Everything works except the Registry Cleaner. The Alt-G to start it works, the Scan for Issues works, the &Fix Selected isssues... Finally works. The only reason the Fix works is I realized that even though the Scan and Fix buttons are enabled, the process is not done (I added statements to "wait" a specified period of time so that I could be SURE the Scan was done). That part of the Fix works.

After the Wait, I tell it to press Alt-F and the Child(?Window comes up. The is the part that defies being automated and is driving me crazy or I am just Stuck on Stupid.

MY logic is that the >> button is highlighted and all I have to do is press the right arrow key or the tab key to go to "Fix Issue". Then I just keep pressing Enter till all the issues are fixed (because I don't know how many issues there are via program control). AutoIt does let you check to see if a button "IsEnabled", BUT the fix issue, fix all selected issues and close buttons ALL seem to have the same ControlID, INSTANCE: Value, CLASS:, etc. so there is nothing unique to key on to tell it to press that button.

Any Help would be appreciated.. Jim.

There is no way to automate cleaning the registry, as that'd be (potentially) incredibly dangerous.

You shouldn't run any Registry cleaner without looking carefully at what it detects - ever. There is no 100% safe registry cleaner, and anyway performance gains are minimal (unless you deleted tenths of thousands of keys, you wouldn't notice any difference) ;)

Aethec, I agree with you but I have used ccleaner over a thousand times and have yet encountered an issue.

pullmyefinger, Looks like I have solved your problem... :) Here is the code I am using and it works perfectly. Well except for one bug I cannot seem to fix and I am wondering if you can help me find the issue... I'll post the code after I list the issue...

When I run the code the cleaner runs auto, then the registry cleaner starts. I run the registry one up to 3 times but for some reason on some computers the code crashes ccleaner on the second loop through. If it did it all the time I could likely find the issue but it is very odd.

;I use a batch file to detect if 32 or 64 bit system and run the appropriate version of the standalone version of ccleaner.

;Any suggestions or ideas to make this code better is appreciated. Thanks.

Here's the code:

AutoItSetOption("MustDeclareVars", 1)
Opt("SendKeyDelay", 100); pauses between sent keystrokes
Opt("WinDetectHiddenText", 1)
Opt("WinSearchChildren", 1)

Dim $Drive
Dim $AppWinTitle

$AppWinTitle = “Piriform CCleaner”
$Drive = StringLeft(@ScriptDir, 2)

OnAutoItStart()

ShellExecute($Drive & “\SST\Tools\1CCleaner\RunCCleaner_32_64.bat”) ;This is the location of ccleaner

WinWait($AppWinTitle)
WinActivate($AppWinTitle)

_WinWaitActive($AppWinTitle, “&Run Cleaner”)
BlockInput(1)
AdlibRegister(_CheckForApp($AppWinTitle), 2000)
ControlClick($AppWinTitle, “&Run Cleaner”, “Button2”, “main”)
BlockInput(0)
Sleep(500)

_WinWaitActive($AppWinTitle, “CLEANING COMPLETE”)
BlockInput(1)
ControlClick($AppWinTitle, “Re&gistry”, “Button5”, “main”)
BlockInput(0)
Sleep(500)

For $i = 1 To 3
_WinWaitActive($AppWinTitle, “&Scan for Issues”)
BlockInput(1)
ControlClick($AppWinTitle, “&Scan for Issues”, “Button2”, “main”)
BlockInput(0)
Sleep(500)

;sleep while the Cancel button is active…
While ControlCommand($AppWinTitle, “&Cancel Scan”, “Button2”, “IsEnabled”, “”)
Sleep(500)
WEnd

If ControlCommand($AppWinTitle, “&Fix selected issues…”, “Button3”, “IsEnabled”, “”) Then
Sleep(1000)
;_WinWaitActive($AppWinTitle, “&Fix selected issues…”)
BlockInput(1)
ControlClick($AppWinTitle, “&Fix selected issues…”, “Button3”, “main”)
BlockInput(0)

Sleep(1000)

If ControlCommand("", "Fix All Selected Issues", "[CLASS:Button; TEXT:Fix All Selected Issues; INSTANCE:1]", "IsVisible", "") Then
	BlockInput(1)
	ControlClick("", "", "[CLASS:Button; TEXT:Fix All Selected Issues; INSTANCE:1]", "main")
	BlockInput(0)

	While ControlCommand("", "Fix All Selected Issues", "[CLASS:Button; TEXT:Fix All Selected Issues; INSTANCE:1]", "IsEnabled", "")
		Sleep(500)
	WEnd

	BlockInput(1)
	ControlClick("", "", "[CLASS:Button; TEXT:Close; INSTANCE:1]", "main")
	BlockInput(0)

ElseIf ControlCommand("", "Fix Issue", "[CLASS:Button; TEXT:Fix Issue; INSTANCE:1]", "IsVisible", "") Then
	BlockInput(1)
	ControlClick("", "", "[CLASS:Button; TEXT:Fix Issue; INSTANCE:1]", "main")
	BlockInput(0)

	While ControlCommand("", "Fix Issue", "[CLASS:Button; TEXT:Fix Issue; INSTANCE:1]", "IsEnabled", "")
		Sleep(500)
	WEnd

	BlockInput(1)
	ControlClick("", "", "[CLASS:Button; TEXT:Close; INSTANCE:1]", "main")
	BlockInput(0)

EndIf

Else

;close CCLeaner
BlockInput(0)
AdlibUnRegister(_CheckForApp($AppWinTitle))

WinClose($AppWinTitle)
WinWaitClose($AppWinTitle)

Exit (0)

EndIf
Sleep(1000)

Next

;close CCLeaner
BlockInput(0)
AdlibUnRegister(_CheckForApp($AppWinTitle))

WinClose($AppWinTitle)
WinWaitClose($AppWinTitle)

Exit (0)

Func _WinWaitActive($title, $text = ‘’)
; window wait functions
While Not WinActive($title, $text)
WinWait($title, $text)
WinActivate($title, $text)
WinWaitActive($title, $text)
WEnd
WinSetOnTop($title, $text, 1)
EndFunc ;==>_WinWaitActive

Func OnAutoItStart()
; single script instance only
If WinExists(@ScriptName & ‘_Interpreter’) Then Exit
AutoItWinSetTitle(@ScriptName & ‘_Interpreter’)
EndFunc ;==>OnAutoItStart

Func _CheckForApp($title)
; Used to scan for something while program is running
; Use AdlibRegister(_CheckForApp($title), 2000) to start scanning
; Use AdlibUnregister(_CheckForApp($title)) to stop scanning
If Not WinExists($title) Then
BlockInput(0)
Exit (0)
;WinClose
EndIf
EndFunc ;==>_CheckForApp

Old thread is Old. but I think your thread was meant well, so I place the long code in code tags :)

Thanks. It was the first time I post here :) So if anyone has any suggestions please let me know :)

Not too sure why it would crash CCleaner... any ideas?

Question does it fail on 32 bit or 64 bit machines, or both.

Criticism

I think your code is doomed at the first hurdle ! !

;I use a batch file to detect if 32 or 64 bit system and run the appropriate version of the standalone version of ccleaner.

This implies that your script does not know whether it is running on 32 or 64 bits.

AutoIt is available in both 32 bit and 64 bit versions according to

http://www.autoitscript.com/site/autoit/downloads/

Is it possible that a 32 bit AutoIt could be misbehaving on a 64 bit machine ?

Perhaps the script could detect and run the correct version of AutoIt before it selects CCleaner ! ! !

Hmm... you've got a point there. I may have to try that. The batch file was detecting properly which version to use based upon 32/64 bit as it can find such from the system info. But I now changed the script to autodetect the system 32/64 bit using AutoIT scripting (without the batch file) but that doesn't change the 32/64 bit of the compiled autoIt script. The problem is that I have ran the 32-bit compiled version on all my systems at home and it does not crash ccleaner. It only crashes on most of the fresh units that were just started up out of the box and some installs were done on it without rebooting, then ccleaner was run! Could it be one of the installs that is tripping up ccleaner?

Does the problem occur only both 32 and 64 bit machines, or is it specific to only one width ?

INVESTIGATION SUGGESTIONS :-

Have earlier versions of CCleaner the same problem - the later versions dig deeper where they never dug before;

Does the problem remain if you configure that ALL the registry cleaning boxes are unchecked,

perhaps one the the registry targets is actually needed for the AutoIt launching of Registry Cleaning.

Well I have to say that it is run on 99% 64-bit and 1% 32-bit systems, but I compiled it as 32-bit just in case a 32-bit system is encountered. This has been occuring at least for the Version 3.x versions of CCleaner.

I guess I should try an older version as well as the suggestion you gave to test it and see what happens. Thanks for the ideas! Not sure when next I will be in the office to test this but hopefully it will be soon! Thanks.