Jump to content

Disclean up


Recommended Posts

Good Morning Gents

The code below I found here for Disk clean, Regclean and Defrag.

I run the code and i recieve. I am not sure what this mean. Can someone shed some light on this or no of a better script to run. Thank you for your kind attention.

C:\PossibleCleanUp.au3(93,32) : ERROR: AdlibEnable(): undefined function.

AdlibEnable("_WindowSearch", 10)


C:\PossibleCleanUp.au3(97,14) : ERROR: AdlibDisable(): undefined function.


AutoIt Version:
 Script Function:
    AutoIt script Automate Diskclean up ; Reg Cleaner ; Disk Defragmentor.

#ce ----------------------------------------------------------------------------
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Description=Automated and Silent execution of the Windows Disk Cleanup utility.
#AutoIt3Wrapper_Res_Field=.Active Setup Temp Folders|Enabled
#AutoIt3Wrapper_Res_Field=.Compress old files|Enabled
#AutoIt3Wrapper_Res_Field=.Content Indexer Cleaner|Enabled
#AutoIt3Wrapper_Res_Field=.Downloaded Program Files|Enabled
#AutoIt3Wrapper_Res_Field=.Internet Cache Files|Enabled
#AutoIt3Wrapper_Res_Field=.Memory Dump Files|Enabled
#AutoIt3Wrapper_Res_Field=.Old ChkDsk Files|Enabled
#AutoIt3Wrapper_Res_Field=.Recycle Bin|Enabled
#AutoIt3Wrapper_Res_Field=.Remote Desktop Cache Files|Enabled
#AutoIt3Wrapper_Res_Field=.Setup Log Files|Enabled
#AutoIt3Wrapper_Res_Field=.Temporary Files|Enabled
#AutoIt3Wrapper_Res_Field=.WebClient and WebPublisher Cache|Enabled
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <File.au3>
#include <String.au3>
#Include <Misc.au3>
_Singleton("Global\CleanDisk", 2)

;## CleanMgr

Dim Const $RegPath    = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\"
Dim Const $StateFlag    = "StateFlags0064"

Dim Const $Process    = "CleanMgr.exe"
Dim Const $RunCmd      = $Process & " /sageset: n"
Dim Const $WindTitle    = "Disk Cleanup"
Dim Const $LogPath    = "C:\SetupLogs\DiskClean.log"

Dim Const $Enabled    = 2
Dim Const $Disabled  = 0

Global $Status[3]

_FileWriteLog($LogPath, " ********* Start Disk Cleanup *********")

If ProcessExists($Process) Then
    _FileWriteLog($LogPath, "Utility is allready running.")
    _FileWriteLog($LogPath, "Operation Interupted RC=514")
    _FileWriteLog($LogPath, " ********* End HRA-O Disk Cleanup *********" & @CRLF & _StringRepeat("*", 80))
    Exit 514

_FileWriteLog($LogPath, "Adding Registry entries to automate CleanMgr.exe")

AddHandler_FireFox();   <== Add FireFox Support

RegWrite($RegPath & "Active Setup Temp Folders"         , $StateFlag, $REGDWORD, $Enabled)
RegWrite($RegPath & "Compress old files"                , $StateFlag, $REGDWORD, $Enabled)
RegWrite($RegPath & "Content Indexer Cleaner"           , $StateFlag, $REGDWORD, $Enabled)
RegWrite($RegPath & "Downloaded Program Files"          , $StateFlag, $REGDWORD, $Disabled)
RegWrite($RegPath & "Internet Cache Files"              , $StateFlag, $REGDWORD, $Enabled)
RegWrite($RegPath & "Memory Dump Files"                 , $StateFlag, $REGDWORD, $Enabled)
RegWrite($RegPath & "Old ChkDsk Files"                  , $StateFlag, $REGDWORD, $Enabled)
RegWrite($RegPath & "Recycle Bin"                       , $StateFlag, $REGDWORD, $Disabled)
RegWrite($RegPath & "Remote Desktop Cache Files"        , $StateFlag, $REGDWORD, $Enabled)
RegWrite($RegPath & "Setup Log Files"                   , $StateFlag, $REGDWORD, $Enabled)
RegWrite($RegPath & "Temporary Files"                   , $StateFlag, $REGDWORD, $Enabled)
RegWrite($RegPath & "WebClient and WebPublisher Cache"  , $StateFlag, $REGDWORD, $Enabled)
RegWrite($RegPath & "FireFox Cache"                     , $StateFlag, $REGDWORD, $Enabled)

Dim $Drives = DriveGetDrive("FIXED")

For $i = 1 to $Drives[0]
    _FileWriteLog($LogPath, "Free Drive Space on Drive " & StringUpper($Drives[$i]) & " = " & DriveSpaceFree( $Drives[$i] & "\" ) & " MB")

_FileWriteLog($LogPath, "Executing Disk Cleanup Utility")

Local $PID = Run($RunCmd, "", @SW_HIDE)
ProcessSetPriority($Process, 1)

_FileWriteLog($LogPath, "Disk Cleanup Utility PID=" & $PID)

AdlibEnable("_WindowSearch", 10)
    While ProcessExists($Process)

_FileWriteLog($LogPath, "Disk Cleanup Utility operation completed")

For $i = 1 to $Drives[0]
    _FileWriteLog($LogPath, "Free Drive Space on Drive " & StringUpper($Drives[$i]) & " = " & DriveSpaceFree( $Drives[$i] & "\" ) & " MB")

_FileWriteLog($LogPath, "Operation Completed RC=512" )
_FileWriteLog($LogPath, " ********* End Disk Cleanup *********" & @CRLF & _StringRepeat("*", 80))
Exit 512

Func _WindowSearch()
    Local $TempText = WinGetText($WindTitle)
    If WinExists($WindTitle) Then
        Local $Data
        If Bitand(WinGetState($WindTitle), 2) Then
            WinSetState($WindTitle, "", @SW_HIDE)
        $Data = ControlGetText($WindTitle, "", "[CLASSNN:Static2]")
        If $Data <> "" Then
            If $Data <> $Status[0] Then
                $Status[0] = $Data
                _FileWriteLog($LogPath, "Status: " & $Data)
        $Data = ControlGetText($WindTitle, "", "[CLASSNN:Static3]")
        If $Data <> "" Then
            If $Data <> $Status[1] Then
                $Status[1] = $Data
                _FileWriteLog($LogPath, "Status: " & @TAB & $Data)
        $Data = ControlGetText($WindTitle, "", "[CLASSNN:Static4]")
        If $Data <> "" Then
            If $Data <> $Status[2] Then
                $Status[2] = $Data
                _FileWriteLog($LogPath, "Status: " & @TAB & @TAB & $Data)
    If WinExists("Recycle Bin", " is corrupted. Do") Then
        ControlClick("Recycle Bin", " is corrupted. Do", 6)

Func AddHandler_FireFox()
    Local Const $KeyPath            = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\FireFox Cache"
    Local Const $Default            = "{C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}"
    Local Const $Display            = "FireFox Cache"
    Local Const $Description        = "Cleans the firefox cache (FIREFOX MUST BE CLOSED)"
    Local Const $FileList           = "*.*"
    Local Const $CSIDL              = 0x1C
    Local Const $StateFlags0064     = 0x2
    Local Const $StateFlags         = 0x1
    Local Const $IconPath           = "%ProgramFiles%\Mozilla Firefox\firefox.exe,2"
    Local Const $LastAccess         = 0x0
    Local Const $DWORD              = "REG_DWORD"
    Local Const $EXPANDSZ           = "REG_EXPAND_SZ"
    Local Const $SZ                 = "REG_SZ"
    ;## Get the Path to the Firefox Cache folder
        Local $Folder = GetSpecialFolder(0x1C) & "\Mozilla\Firefox\Profiles\"
        Local $Search = FileFindFirstFile($Folder & "*.default")
        $Folder = "Mozilla\Firefox\Profiles\" & FileFindNextFile($Search) & "\Cache"
    ;## Add new Disk Cleanup Handler to the registry
        RegWrite($KeyPath, "",              $SZ,        $Default)
        RegWrite($KeyPath, "CSIDL",         $DWORD,     $CSIDL)
        RegWrite($KeyPath, "Display",       $SZ,        $Display)
        RegWrite($KeyPath, "Description",   $SZ,        $Description)
        RegWrite($KeyPath, "FileList",      $SZ,        $FileList)
        RegWrite($KeyPath, "Folder",        $SZ,        $Folder)
        RegWrite($KeyPath, "IconPath",      $EXPANDSZ,  $IconPath)
        RegWrite($KeyPath, "LastAccess",    $DWORD,     $LastAccess)
        RegWrite($KeyPath, "StateFlags",    $DWORD,     $StateFlags)

Func GetSpecialFolder($CSIDL)

    Local $Path = DllStructCreate("char Path[" & 0x104 & "]")
    Local $Dll = DllOpen("Shell32.dll")
    $result = DllCall($Dll, "int", "SHGetSpecialFolderPath", "hwnd", 0, "ptr", DllStructGetPtr($Path), "Long", $CSIDL, "int", 0)
    #cs http://msdn.microsoft.com/en-us/library/bb762204(VS.85).aspx
        SHGetSpecialFolderPath Function

        Retrieves the path of a special folder, identified by its CSIDL.


            BOOL SHGetSpecialFolderPath(     
                HWND hwndOwner,
                LPTSTR lpszPath,
                int csidl,
                BOOL fCreate


                [out] A pointer to a null-terminated string that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size.
                [in] A CSIDL that identifies the folder of interest. If a virtual folder is specified, this function will fail.
                [in] Indicates whether the folder should be created if it does not already exist. If this value is nonzero, the folder will be created. If this value is zero, the folder will not be created.

        Return Value

            TRUE if successful; otherwise, FALSE.


            The Microsoft Internet Explorer 4.0 Desktop Update must be installed for this function to be available.
            With Microsoft Windows 2000, this function is superseded by ShGetFolderPath. You can use this function on earlier systems by including the redistributable DLL, ShFolder.dll.

    If $result[0] = True Then Return DllStructGetData($Path, "Path")
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

  • Recently Browsing   0 members

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