Jump to content

CCleaner Script


Recommended Posts

I am using ccleaner 3.0 and am trying to automate the registry cleaning.

everything works for the Scan Issues part, the Fix Selected Issues... button, but when I click fix selected issues:

It gives you a subwindow/child window with the ">>" "Fix Issue" "Fix All Selected Issues" and Close Buttons.

When this sub-window is opened the main window goes inactive and you can't get it activated till you close the aforementioned window.

HOW do I get it to press the right arrow key twice, then press enter on "Fix All Selected Issues", then do the "Close" button to end the program????

I have tried sending the ASCii codes 0157 and 0166,{Right) and {Enter} and nothing works. These are pseudocodes for the correct keystrokes; I know

they won't work. I tried these in conjunction with Ifs, while loops, do loops, control command/controlclick and NOTHING works.

I am getting really tired of going over the same thing and getting the same errors :x I just want this to work finally and be done with it.

Any help would be really appreciated. This is the first script I have written so tailor your explanation(s) accordingly.

If I need to read more I will do that. What I have done is below:

; SCAN REGISTRY ---------------------------------------------------------

Sleep(2000) ; Wait

Send("!G") ; Clean Registry

Send("S") ; Scan for Issues

Sleep(1000) ; Wait (Cancel Scan enabled)

; Scan for Issues **********************************************************

While ControlCommand("Piriform CCleaner","","Cancel Scan","IsEnabled","")

Sleep(100)

WEnd

Sleep(30000) ; **** Wait for Fix Selected Issues to become active ****

WinActivate("Piriform CCleaner")

WinWaitActive("Piriform CCleaner","")

; This works (the IF below shows first fix); This is the Outer loop that is SCAN AND FIX Issues

If ControlCommand("Piriform CCleaner","","&Fix selected issues...","IsEnabled","") OR ControlCommand("Piriform CCleaner","","Fix selected issues...","IsEnabled","") Then

Send("!F")

; Sleep(5000) ; Wait for Child Window

; SCRIPT WORKS TO HERE ********************** INNER LOOP FOR THE FIX ALL SELECTED ISSUES

; THIS IS THE ONLY PART THAT DOES NOT WORK.

If ControlCommand("Piriform CCleaner","","Fix All Selected Issues","IsEnabled","") OR ControlCommand("Piriform CCleaner","","Fix Issue","IsEnabled","") Then

If ControlCommand("",">>","IsEnabled","") Then

MsgBox(0, "FASI"," Inside >> ",5)

ControlClick("",">>","left")

Send("{RIGHT}") ; press right arrow ASC 0157

Send("{RIGHT}") ; press right arrow ASC 0157

Send("{ENTER}") ; press enter ASC 0166

;Sleep(2500)

;Send("!{F4}")

Else

;Send("!{F4}")

EndIf

EndIf

EndIf

;WinActivate("Piriform CCleaner")

;WinWaitActive("Piriform CCleaner","")

;Sleep(3000)

;Send("!{F4}")

Link to comment
Share on other sites

Please use AutoIt Tag for your script !

And CCleaner has some switches for run silently with your own settings :

CCleaner.exe /AUTO CCleaner runs silently and automatically, using the current set of saved options to clean the PC.

CCleaner then exits.

CCleaner.exe /AUTO /SHUTDOWN CCleaner runs silently and automatically, using the current set of saved options to clean the PC.

Windows then shuts down automatically.

http://www.piriform.com/docs/ccleaner/advanced-usage/command-line-parameters

I put it at the start of windows for a regular cleaning, it's more easy ! Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Please note from the site:

You cannot currently run the Registry cleaner through a command-line parameter!

One can select the contoll by sending the TAB key(s) and then the Enter key.

You're right, it's like this :

RegWrite ( 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run', 'ccleaner', "REG_SZ", '"' & @ProgramFilesDir & '\CCleaner\CCleaner.exe" /AUTO' )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Please note from the site:

You cannot currently run the Registry cleaner through a command-line parameter!

One can select the contoll by sending the TAB key(s) and then the Enter key.

Doesn't work (the tab, tab, enter sequence).

Actually,

There are 3 or 4 command buttons: ">>" to scroll through the issues, one at a time,

"Fix Issue" to fix the current selected issue from above,

"Fix All Selected Issues" self explanatory and

"Close".

I tried to find something unique about the command buttons (other than the text), but all have the same

Instance, Class, ID, etc.

Used controlcommmand, commandclick, controlclick and nothing works.

A past reply said to run ccleaner with a couple switches but that does not seem to work either.

I want to see what the machine is Doing and not have it run in Silent Mode. PLUS, the documentation

leaves alot to be desired.

The aforementioned command's explanations are weak. It doesn't help that this is the first script I

have ever written..

Link to comment
Share on other sites

I'm stuck. On my previous version al worked ok with the TAB keys and controll click BUT

with the latest v3.01.1327 can not seem to get any keys set to this program.

Some one more clever than me will have to solve this.

U can use the ccleaner's program GUI to save all settings to an ini file. (I think it's ccleaner.ini, within the default C:\program files\ccleaner folder)

Then run with ccleaner.exe /Auto

Link to comment
Share on other sites

Thanx for all the replys.

BUT the problem looks like this:

pullmyefinger wants to clean the registery by sending key(s) etc to CCleaner.

CCleaner does not support the registery cleaning bit through the /Auto run and there is no setting in the .INI to cater for this.

So it seems that even sending control click etc does not work. (However if you do this manually in CCleaner it does work!)

Link to comment
Share on other sites

It appears to me that if you run the command "ccleaner.exe /registry", it pulls up Ccleaner at the registry section. Then send an "s" and it will scan. I don't know how to get AutoIt to know when the scan is complete (maybe someone could help with this part), but then you would need to send an "f", two right arrows and an enter. That would make it clean the registry automatically.

#include <ByteMe.au3>

Link to comment
Share on other sites

It is suggested on the ccleaner site to evaluate each item in the registry fix dialog and not use fix all,

but if you want to automate it for your own purposes read on..

The ws_popup style #32770 dialog class fix reg issues window is not identified by

the AutoIt v3 Window Info tool. it sees one large static control...

I prefer to use Winspector or Window Detective

http://www.softpedia.com/get/Security/Security-Related/Winspector.shtml

http://sourceforge.net/projects/windowdetective/

these two apps identify the controls in this window

Run this example with the ccleaner fix registry issues dialog already open

This example uses verified window/control handles with the control commands

For some reason CCleaner allows multiple instances...

so a multiple instance check is added.

EDIT: noticed problem with _ControlGetClassnameNN() and .NET controls - replaced GetParent() with GetAncestor()

#include <WinAPI.au3>
#include <Array.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

_CCleanerDlgTest()

Func _CCleanerDlgTest()

    Local $hWnd, $hWndDlg = 0, $sDlgFixBtn, $sDlgCloseBtn, $PID, $iTime, _
    $aDlgList, $hFASIBtn, $hCloseBtn, $iRet, $sText, $sClassNameNN, $DlgCtrlID

    ;CCleaner v3.01.1327
    Local $sProcName = "CCleaner.exe"                       ;target app process name
    Local $sMain = "[TITLE:Piriform CCleaner]"              ;target app main window title ;"[TITLE:Piriform CCleaner;CLASS:#32770]"
    Local $sMainTitle = "Piriform CCleaner"                 ;target app title
    Local $sClassNameDlg = "#32770"                         ;target app main window class
    Local $sClassDlg = "[CLASS:#32770]"                     ;target dialog class

    ;Instance and ID are fixed values in app code, but could change between versions if dialogs are changed
    ;the button text would probably remain the same (for reasons of user and existing documentation issues if changed).
    ;it's your choice. I prefer to use Class and Control ID/instance for my own use.
    $sDlgFixBtn = "[TEXT:Fix All Selected Issues; CLASS:Button]"    ;button Text and Class
    ;$sDlgFixBtn = "[TEXT:Fix All Selected Issues; ID:1100]";button Text and ID
    ;$sDlgFixBtn = "[CLASS:Button; INSTANCE:4]";button Class and Instance
    ;$sDlgFixBtn = "[CLASS:Button; ID:1100]"    ;button Class and ID

    $sDlgCloseBtn = "[TEXT:Close; CLASS:Button]"    ;button Text and Class
    ;$sDlgCloseBtn = "[TEXT:Close; ID:1104]";button Text and ID
    ;$sDlgCloseBtn = "[CLASS:Button; INSTANCE:5]";button Class and Instance
    ;$sDlgCloseBtn = "[CLASS:Button; ID:1104]"  ;button Class and ID

    ;multiple instance check - get PID of parent window
    Local $aProcList = ProcessList($sProcName)
    If @error Or IsArray($aProcList) = 0 Then Exit ConsoleWrite("! Error: Failed to retrieve process list!" & @CRLF)
    If $aProcList[0][0] = 0 Then Exit ConsoleWrite("! Error: No instance of CCleaner running!" & @CRLF)
    If $aProcList[0][0] > 1 Then Exit ConsoleWrite("! Error: Multiple instances of CCleaner running!" & @CRLF)
    $PID = $aProcList[1][1]

    ;$iRet = WinActivate($sMain);make window active
    ;$iRet = WinWaitActive($sMain, "", 3);wait
    $hWnd = WinGetHandle($sMain);get win handle for use with all control commands
    ;verify that handle belongs to our target window: check IsHWnd() and Title (Class and PID)
    If Not IsHWnd($hWnd) Or WinGetTitle($hWnd) <> $sMainTitle Then ; _WinAPI_GetClassName($hWnd) <> $sClassNameDlg
    ;If Not IsHWnd($hWnd) Or WinGetProcess($hWnd) <> $PID Then ;verify pid is for target app process
        ConsoleWrite("! Error: Failed to retrieve handle" & @CRLF)
        Exit
    EndIf

    ;enumerate all (visible or not) #32770 dialog class windows until child window of parent process found or timeout expires
    $iTime = TimerInit()
    Do
        $aDlgList = WinList($sClassDlg);$aDlgList[0][0] = 0 if no matching windows
        For $i = 1 to $aDlgList[0][0] ;skips this loop if $aDlgList[0][0] = 0
            ;If BitAnd(WinGetState($aDlgList[$i][1]), 2) <> 2 Then ContinueLoop ;ignore hidden #32770 dialog windows
            ;verify #32770 dialog belongs to parent process and is not parent window of same class
            If WinGetProcess($aDlgList[$i][1]) = $PID And WinGetTitle($aDlgList[$i][1]) <> $sMainTitle Then ; #32770 dialog is a child of parent process
                $hWndDlg = $aDlgList[$i][1]; #32770 dialog handle
                ExitLoop 2 ;break out of both loops
            EndIf
        Next
        Sleep(50)

    Until TimerDiff($iTime) >= 3000 ; 3 sec timeout


    If $hWndDlg = 0 Then Exit ConsoleWrite("! Error: Failed to retrieve Fix All dialog" & @CRLF)
    ConsoleWrite("-#32770 Dialog - Fix Issues Popup Handle: " & $hWndDlg & @CRLF)

    ;$sText = WinGetText($hWndDlg);retrieve all dialog text
    ;ConsoleWrite("-#32770 Dialog: " & $sText & @CRLF)

    $iRet = WinActivate($hWndDlg);make window active before clicking button
    $iRet = WinWaitActive($hWndDlg, "", 2);wait for window to be active


;minimal error handling in this section, add your own


    ;arrow buttons - add  handle verification code to these like examples shown below
    Local $hLArrowBtn = ControlGetHandle($hWndDlg, "", "[TEXT:<<; CLASS:Button]");instance 1 ID 1097
    Local $hRArrowBtn = ControlGetHandle($hWndDlg, "", "[TEXT:>>; CLASS:Button]");instance 2 ID 1098
    $iRet = ControlFocus($hWndDlg, "", $hRArrowBtn)
    Sleep(2000)
    $iRet = ControlClick($hWndDlg, "", $hRArrowBtn)
    Sleep(2000)
    $iRet = ControlClick($hWndDlg, "", $hRArrowBtn)
    Sleep(2000)



    ;get Fix All Selected Issues button
    $hFASIBtn = ControlGetHandle($hWndDlg, "", $sDlgFixBtn)
    If Not IsHWnd($hFASIBtn) Or ControlGetText($hWndDlg, "", $hFASIBtn) <> "Fix All Selected Issues" Then
        ConsoleWrite("! Error: Failed to retrieve Fix All button handle" & @CRLF)
        ;$hFASIBtn = ControlGetHandle($hWndDlg, "", "[CLASS:Button; ID:1100]")
        ;$hFASIBtn = ControlGetHandle($hWndDlg, "", "[CLASS:Button; INSTANCE:4]")
        ;$hFASIBtn = _WinAPI_GetDlgItem($hWndDlg, "1100")
        Exit
    EndIf

    ;get close button
    $hCloseBtn = ControlGetHandle($hWndDlg, "", $sDlgCloseBtn)
    If Not IsHWnd($hCloseBtn) Or ControlGetText($hWndDlg, "", $hCloseBtn) <> "Close" Then
        ConsoleWrite("! Error: Failed to retrieve Close button handle" & @CRLF)
        ;$hCloseBtn = ControlGetHandle($hWndDlg, "", "[CLASS:Button; ID:1104]")
        ;$hCloseBtn = ControlGetHandle($hWndDlg, "", "[CLASS:Button; INSTANCE:5]")
        ;$hCloseBtn = _WinAPI_GetDlgItem($hWndDlg, "1104")
        Exit
    EndIf

;uncomment to fix all issues
#cs
    ;click Fix All Selected Issues button
    ;_WinAPI_SetFocus($hFASIBtn);sets Keyboard focus to Button4 - visually highlights button,
    ;as tabbing between controls does, in practice not a good idea to use, as keyboard could interrupt script,
    ;but for script testing with sleep() between steps you can see what control is selected next more clearly than with controlfocus().

    $iRet = ControlFocus($hWndDlg, "", $hFASIBtn);sets Input focus to Button4
    $iRet = ControlClick($hWndDlg, "", $hFASIBtn);click...

    ;verify button now disabled after clicking
    If ControlCommand($hWndDlg, "", $hFASIBtn, "IsEnabled", "") <> 0 Then
        ConsoleWrite("! Error: Failed to click fix button, trying alternative method" & @CRLF)
        $iRet = ControlSend($hWndDlg, "", $hFASIBtn, "{SPACE}")
        If ControlCommand($hWndDlg, "", $hFASIBtn, "IsEnabled", "") <> 0 Then
            ConsoleWrite("! Error: Alternative method failed. Exiting..." & @CRLF)
        Else
            ConsoleWrite("! Alternative method succeeded" & @CRLF)
        EndIf
    EndIf
#ce

    ;click close button
    $iRet = ControlFocus($hWndDlg, "", $hCloseBtn);set input focus to Button4
    $iRet = ControlClick($hWndDlg, "", $hCloseBtn);click...
    ;$iRet = ControlSend($hWndDlg, "", $hCloseBtn, "{SPACE}")

    If ControlCommand($hWndDlg, "", $hCloseBtn, "IsEnabled", "") <> 0 Then
        ConsoleWrite("! Error: Failed to click close button" & @CRLF)
    EndIf

    ;example of other functions that can be used to verify a control
    ;$sClassNameNN = _ControlGetClassnameNN($hFASIBtn) ;returns class and instance for control handle
    ;$DlgCtrlID = _WinAPI_GetDlgCtrlID($hFASIBtn);returns control ID for control handle
    ;If $sClassNameNN <> "Button4" Then Exit ; verify control button Class and Instance
    ;If $DlgCtrlID <> 1100 Then Exit ;verify button is correct control ID
    ;ConsoleWrite('- _ControlGetClassnameNN() = ' & $sClassNameNN & @crlf)
    ;ConsoleWrite('- _WinAPI_GetDlgCtrlID() = ' & $DlgCtrlID & @crlf)

EndFunc


Func _ControlGetClassnameNN($hControl)
    ;Author: Valik
    If Not IsHWnd($hControl) Then Return SetError(1, 0, "")
    ;Local Const $hParent = _WinAPI_GetParent($hControl)
    Local Const $hParent = _WinAPI_GetAncestor($hControl, $GA_ROOT)
    If Not $hParent Then Return SetError(2, 0, "")
    Local Const $sList = WinGetClassList($hParent)
    Local $aList = StringSplit(StringTrimRight($sList, 1), @LF, 2)
    _ArraySort($aList)
     Local $nInstance, $sLastClass, $sComposite
     For $i = 0 To UBound($aList) - 1
         If $sLastClass <> $aList[$i] Then
            $sLastClass = $aList[$i]
            $nInstance = 1
        EndIf
        $sComposite = $sLastClass & $nInstance
        If ControlGetHandle($hParent, "", $sComposite) = $hControl Then Return $sComposite
        $nInstance += 1
    Next
    Return SetError(3, 0, "")
EndFunc    ; _ControlGetClassnameNN()
Edited by rover

I see fascists...

Link to comment
Share on other sites

@sleepydvdr: If controlclick doesn't work, try mouseclick (maybe with WinGetPos) = Tried not working.

@sleepydvdr: command "ccleaner.exe /registry" = working but not getting any further.

I actually thrown all code out and started from scratch. This is it:

RunWait("c:\program files\ccleaner\ccleaner.exe /registry"); Working and open at the registry part
sleep(5000)
ControlClick("Piriform CCleaner","","[CLASS:ATL:005A8268; INSTANCE:1]"); not working!
sleep(500)
send("s");not working
sleep(500)
send("!s");not working
sleep(5000)
MouseMove(1,1);not working
sleep(500)
mousemove(@DesktopWidth, @DesktopHeight);not working
sleep(500)
MouseMove(456, 583);not working
sleep(500)
$size = WinGetPos("[active]");works
MsgBox(0, "Active window stats (x,y,width,height):", $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3]);works
;In the INI file I actualy set these settings and it opens accordingly
MouseClick("left",456, 583,2);not working
sleep(500)

MouseClick("primary",456, 583,2); Not WorKing!
Link to comment
Share on other sites

Rover thanx with that HUGE insight. Did some changes and some unauthorized short cuts so this seems to behave better:

#RequireAdmin; <<  ====  Makes Vista Behave normally
Opt("WinTitleMatchMode", 1)
Run("c:\program files\ccleaner\ccleaner.exe /registry")

While Not WinWaitActive("Piriform CCleaner", "", 10)
    WinActivate("Piriform CCleaner", "")
WEnd
Sleep(500)
Send("!s")
$begin = TimerInit()
While Not ControlCommand("Piriform CCleaner", "", "&Fix selected issues...", "IsEnabled", "") Or ControlCommand("Piriform CCleaner", "", "Fix selected issues...", "IsEnabled", "")
    Sleep(13)
    $dif = TimerDiff($begin)
    If $dif > 15000 Then
        MsgBox(0, '', 'No Scan to perform!', 5)
        WinActivate("Piriform CCleaner", "")
        Send("!{F4}")
        Exit
    EndIf
WEnd
Send("!F")
WinWaitActive("CCleaner", "")
Send("!y")
WinWaitActive("Save As", "")
Send("!s")
Send("{tab 2}")
Send("{enter}")
While Not ControlCommand("", "", "Close", "IsEnabled", "")
    Sleep(14)
WEnd
Send("{tab}")
Send("{enter}")
WinActivate("Piriform CCleaner", "")
Send("!{F4}")
Link to comment
Share on other sites

  • 6 months later...

Hi,

Just stumbled across this thread just after creating my own script. This is working for me on Windows 7 (64 bit) with CCleaner 3.08.

## Date (yyyymmdd): 20110705
## Name:            ccregclean.au3
## Author:          Colin Campbell
## Blog:            http://nerddnotes.blogspot.com/

## CCleaner Registry Clean Unattended.

$cleaner = "C:\Program Files\CCleaner\CCleaner64.exe /registry"

## Run Cleaner.
Run($cleaner)

$title = "[CLASS:#32770]"
$text = "Scan for Issues"
WinWait($title, $text)
WinActivate($title, $text)

## Scan for Issues
ControlClick($title, $text, "Button2")

## Wait for Scan to finish
While Not ControlCommand($title, $text, "&Scan for Issues", "IsEnabled")
    Sleep(5000)
WEnd

## If issues found
If ControlCommand($title, $text, "Button3", "IsEnabled") Then
    ## Fix selected issues
    ControlClick($title, $text, "Button3")

    ## Click fix all on popup
    $text = "Fix All Selected Issues"
    WinWait($title, $text)
    ControlClick($title, $text, "Button4")
    
    ## Wait till done
    While ControlCommand($title, $text, "Button4", "IsEnabled")
        Sleep(10)
    WEnd
    
    ## Close Popup
    ControlClick($title, $text, "Button5")
EndIf

$text = "Scan for Issues"
WinClose($title, $text)

## Done!
Sleep(1000)

For this to work you have to deselect "Show prompt to backup registry issues" in the Advanced options.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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