Jump to content

Compiled EXE Script Stops After Install


DPiddy
 Share

Recommended Posts

Hello,

Just trying to teach myself some AutoIT by doing an installer for CCleaner. The script runs when not compiled but ends after CCleaner finishes the install.

I want the script to close the install window and disable monitoring.

I have attached the AU3 file.

Just put the ccleaner install in "c:\users\" and rename it ccsetup.exe

http://download.ccleaner.com/ccsetup539.exe

I have read some harsh replies here so go easy on me please.

CCleaner.au3

Link to comment
Share on other sites

  • Moderators

@DPiddy Welcome to the forum. Piriform supplies a host of command line parameters; you are going to be much better off writing your script to make use of these rather than trying to automate the various pages and buttons of the installation wizard. I would suggest starting here:

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanks but the code works pre-compile. I am doing this to learn AutoIT. Maybe you could suggest another installer I could use to run code on after the installer finishes?

Spoiler
;#RequireAdmin
FileInstall("C:\Users\ccsetup.exe", "C:\ccsetup.exe", 1)
SplashTextOn("CCleaner", "Installing Please do not touch the keyboard or mouse until installation is complete.", 300, 100)
AutoItSetOption('MouseCoordMode', 0)
Run('C:\ccsetup.exe')
Install()
Func Install() ;~ Install Program
 Local $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup")
 If $CCHandle = 0x00000000 Then
  Sleep(1500)
  Install()
 EndIf
 WinActivate($CCHandle, '')
 WinWaitActive($CCHandle, '')
 Sleep(50)
 ControlClick($CCHandle, "", 1005)
 ControlCommand($CCHandle, "", 'Button4', 'UnCheck')
 ControlCommand($CCHandle, "", 'Button5', 'Check')
 ControlCommand($CCHandle, "", 'Button6', 'UnCheck')
 ControlCommand($CCHandle, "", 'Button7', 'UnCheck')
 ControlCommand($CCHandle, "", 'Button8', 'UnCheck')
 ControlClick($CCHandle, "", 'Button3')
 Sleep(100)
 Open()
EndFunc   ;==>Install
Func Open() ;~Program installed. Run it
 Local $CCHandle1 = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup Completed")
 If $CCHandle1 = 0x00000000 Then
  Sleep(1500)
  Open()
 EndIf
 WinActivate($CCHandle1)
 WinWaitActive($CCHandle1)
 Sleep(50)
 ControlCommand($CCHandle1, "", 'Button3', 'UnCheck')
 ControlClick($CCHandle1, "", 'Button1')
 Sleep(50)
 StopMon()
EndFunc   ;==>Open
Func StopMon() ;~Disable Monitoring
 Local $CCHandle2 = WinGetHandle("Piriform CCleaner")
 If $CCHandle2 = 0x00000000 Then
  Sleep(1500)
  StopMon()
 EndIf
 WinActivate($CCHandle2)
 WinWaitActive($CCHandle2)
 Sleep(50)
 ControlClick($CCHandle2, "&Options", 1003)
 Sleep(300)
 ControlClick($CCHandle2, "Monitoring", 1021)
 Sleep(300)
 Send("{ESC}")
 Sleep(300)
 ControlCommand($CCHandle2, "Enable &system monitoring", "Button12", 'UnCheck')
 Sleep(300)
 ControlCommand($CCHandle2, "&Enable Active Monitoring", "Button15", 'UnCheck')
 WinWait("Disable Active Monitoring")
 WinActivate("Disable Active Monitoring")
 WinWaitActive("Disable Active Monitoring")
 Sleep(50)
 Send("{TAB 2}")
 Sleep(300)
 Send("{ENTER}")
 Sleep(300)
 ControlClick($CCHandle2, "&Cleaner", 1000)
 FileDelete('C:\ccsetup.exe')
 Exit
EndFunc   ;==>StopMon

 

Link to comment
Share on other sites

  • Moderators

Unfortunately you have a number of Sleeps and Sends in there; Send especially being very unreliable (another reason we suggest using command line when possible). Learning AutoIt is certainly the goal, but learning to code smarter not harder will serve you well no matter what language you use :)

Perhaps someone will wander by that wants to download CCleaner and step through your code line by line to see why it is failing. In the meantime, a couple of suggestions:

  • You have almost no error checking in your script; at most I see a couple of times where you call WinActivate twice. You might look on the Wiki for error checking and add that in.
  • Doing so will help you narrow down exactly where it is failing or hanging (line number). If you share that here, it will help those helping you by shortening the amount of work they need to reproduce.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Another approach to simplify your job is not to mess with automating the entire installation process. Get CCleaner Portable Build instead. Unpack anywhere and voila https://www.ccleaner.com/ccleaner/download/portable. Portable version unlike installer don't contain junk files,toolbars and extra programs such as google chrome.

Edited by Au3Builder
Link to comment
Share on other sites

  • Moderators
55 minutes ago, Au3Builder said:

Get CCleaner Portable Build instead. 

Great if you are doing it for one machine, and want to repeat the download process every time you have updates. Way more administrative overhead than necessary if you are managing even 2 PCs, let alone a corporate setting.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

10 hours ago, JLogan3o13 said:

Great if you are doing it for one machine, and want to repeat the download process every time you have updates. Way more administrative overhead than necessary if you are managing even 2 PCs, let alone a corporate setting.

Excuse me but what exactly do you mean by that?

Edited by Au3Builder
Link to comment
Share on other sites

Thanks guys. The "compiled" script stops on line 21:

ControlClick($CCHandle, "", 'Button3')
 Sleep(100)
 Open()
EndFunc   ;==>Install
Func Open() ;~Program installed. Run it

I was using message boxes for error checking but if it is compiled would incorporating a log file be the best option for that?

Am i missing an:

#include *** ;~ ?

Link to comment
Share on other sites

  • Developers

You are being pretty vague here....Which one  is Line 21?
There actually is no line shows where the script will stop for longer than 100 ms.

Jos
 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

i added the code in the hidden content on the 3rd post. Not sure how to post the code to make it colorful?

As soon as the finish button is visible autoit thinks the script is finished too and quits. 21 was the top line in my post you replied to.

Link to comment
Share on other sites

  • Developers

Use the <> in the menubar to post code. I highly doubt that line 21 is the issue. This piece of code is is wrong logic and can create a recursion level error as well:

Func Install() ;~ Install Program
    Local $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup")
    If $CCHandle = 0x00000000 Then
        Sleep(1500)
        Install()
    EndIf

Should be something like: (But still could be waiting forever so might want to put a limit to the wait time there)

Func Install() ;~ Install Program
    Local $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup")
    While $CCHandle = 0x00000000 Then
        Sleep(1500)
        $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup")
    WEnd

This code could be blocking as well as it is an endless wait:

WinActivate($CCHandle, '')
    WinWaitActive($CCHandle, '')

Just add a timer in the last line and test for that to trigger an error.

Your other Func's have the same issue with the recursion and need to be changed as well.

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ok this seems wrong/sloppy but i got it working (i cleaned up the sleeps too). i compiled the install script with the installer. then compiled that script with the rest of of it and added a RunWait :-/

is there a way around this maybe incorporating ProcessWaitClose?

Step 1 (compiled as 'CCleaner1.exe')

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
FileInstall("C:\Users\ccsetup.exe", "C:\ccsetup.exe", 1)

AutoItSetOption('MouseCoordMode', 0)

Run('C:\ccsetup.exe')

Install()

Func Install()

    Local $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup")

    While $CCHandle = 0x00000000
        Sleep(1500)
        $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup")
    WEnd

    WinWait($CCHandle)
    WinActivate($CCHandle)
    WinWaitActive($CCHandle, '', 18)

    ControlClick($CCHandle, "", 1005)
    ControlCommand($CCHandle, "", 'Button4', 'UnCheck')
    ControlCommand($CCHandle, "", 'Button5', 'Check')
    ControlCommand($CCHandle, "", 'Button6', 'UnCheck')
    ControlCommand($CCHandle, "", 'Button7', 'UnCheck')
    ControlCommand($CCHandle, "", 'Button8', 'UnCheck')
    ControlClick($CCHandle, "", 'Button3')

EndFunc   ;==>Install

Step 2

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

FileInstall("C:\Users\CCleaner1.exe", "C:\CCleaner1.exe", 1)

SplashTextOn("CCleaner", "Installing Please do not touch the keyboard or mouse until installation is complete.", 300, 100)

AutoItSetOption('MouseCoordMode', 0)

RunWait('C:\CCleaner1.exe')

While 1

    Local $CCHandle1 = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup Completed")

    While $CCHandle1 = 0x00000000
        Sleep(1500)
        $CCHandle1 = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup Completed")
    WEnd

    WinWait($CCHandle1)
    WinActivate($CCHandle1)
    WinWaitActive($CCHandle1, '', 18)

    ControlCommand($CCHandle1, "", 'Button3', 'UnCheck')
    ControlClick($CCHandle1, "", 'Button1')

    Local $CCHandle2 = WinGetHandle("Piriform CCleaner")

    While $CCHandle2 = 0x00000000
        Sleep(1500)
        $CCHandle2 = WinGetHandle("Piriform CCleaner")
    WEnd

    WinWait($CCHandle2)
    WinActivate($CCHandle2)
    WinWaitActive($CCHandle2, '', 18)


    ControlClick($CCHandle2, "&Options", 1003)

    WinWaitActive($CCHandle2)

    ControlClick($CCHandle2, "Monitoring", 1021)

    Send("{ESC}")

    WinWaitActive($CCHandle2, "Enable &system monitoring")

    ControlCommand($CCHandle2, "Enable &system monitoring", "Button12", 'UnCheck')

    WinWaitActive($CCHandle2, "&Enable Active Monitoring")

    ControlCommand($CCHandle2, "&Enable Active Monitoring", "Button15", 'UnCheck')

    Local $CCHandle3 = WinGetHandle("Disable Active Monitoring")

    While $CCHandle3 = 0x00000000
        Sleep(1500)
        $CCHandle3 = WinGetHandle("Disable Active Monitoring")
    WEnd

    WinWait($CCHandle3)
    WinActivate($CCHandle3)
    WinWaitActive($CCHandle3, '', 18)
    Sleep(50)

    Send("{TAB 2}")

    Send("{ENTER}")

    ControlClick($CCHandle2, "&Cleaner", 1000)

    FileDelete('C:\CCleaner1.exe')
    FileDelete('C:\ccsetup.exe')

    If Not FileExists('C:\ccsetup.exe') Then
        Exit
    EndIf

WEnd

 

Edited by DPiddy
Link to comment
Share on other sites

RunWait stops the script until whatever you ran with it closes, that's probably half the problem you were having.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

On 2/23/2018 at 5:44 PM, BrewManNH said:

RunWait stops the script until whatever you ran with it closes, that's probably half the problem you were having.

Sorry @BrewManNH my OG script did not have runwait i am aware of how it works. In this later attempt i split the scripts and compiled them into each other. then i used runwait to trick the script into running after the install finished. the original problem is that when you combine step one and step two (and remove runwait) the single compiled script stops just before you see the finish button on CCleaner. if the script is not compiled it will run. here is the original script please note line 34 "Install Button. Compiled Script Stops Here":

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

FileInstall("C:\Users\ccsetup.exe", "C:\ccsetup.exe", 1)

SplashTextOn("CCleaner", "Installing Please do not touch the keyboard or mouse until installation is complete.", 300, 100)

AutoItSetOption('MouseCoordMode', 0)

Run('C:\ccsetup.exe')

While FileExists('C:\ccsetup.exe')

    Local $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup")

    While $CCHandle = 0x00000000
        Sleep(1500)
        $CCHandle = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup")
    WEnd

    WinWait($CCHandle)
    WinActivate($CCHandle)
    WinWaitActive($CCHandle, '', 18)

    ControlClick($CCHandle, "", 1005)
    ControlCommand($CCHandle, "", 'Button4', 'UnCheck')
    ControlCommand($CCHandle, "", 'Button5', 'Check')
    ControlCommand($CCHandle, "", 'Button6', 'UnCheck')
    ControlCommand($CCHandle, "", 'Button7', 'UnCheck')
    ControlCommand($CCHandle, "", 'Button8', 'UnCheck')
    ControlClick($CCHandle, "", 'Button3') ;~ Install Button. Compiled Script Stops Here

    Local $CCHandle1 = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup Completed")

    While $CCHandle1 = 0x00000000
        Sleep(1500)
        $CCHandle1 = WinGetHandle("[CLASS:#32770]", "CCleaner v5.39 Setup Completed")
    WEnd

    WinWait($CCHandle1)
    WinActivate($CCHandle1)
    WinWaitActive($CCHandle1, '', 18)

    ControlCommand($CCHandle1, "", 'Button3', 'UnCheck')
    ControlClick($CCHandle1, "", 'Button1') ;~ Finish Button. Install Complete

    Local $CCHandle2 = WinGetHandle("Piriform CCleaner")

    While $CCHandle2 = 0x00000000
        Sleep(1500)
        $CCHandle2 = WinGetHandle("Piriform CCleaner")
    WEnd

    ;~  Wait for program to open
    WinWait($CCHandle2)
    WinActivate($CCHandle2)
    WinWaitActive($CCHandle2, '', 18)

    ControlClick($CCHandle2, "&Options", 1003) ;~ Go to Options

    WinActivate($CCHandle2)
    WinWaitActive($CCHandle2)

    ControlClick($CCHandle2, "Monitoring", 1021) ;~ Go to Monitoring

    Send("{ESC}")

    ;~ Disable Monitoring
    WinWaitActive($CCHandle2, "Enable &system monitoring")

    ControlCommand($CCHandle2, "Enable &system monitoring", "Button12", 'UnCheck')

    WinWaitActive($CCHandle2, "&Enable Active Monitoring")

    ControlCommand($CCHandle2, "&Enable Active Monitoring", "Button15", 'UnCheck')

    Local $CCHandle3 = WinGetHandle("Disable Active Monitoring")

    While $CCHandle3 = 0x00000000
        Sleep(1500)
        $CCHandle3 = WinGetHandle("Disable Active Monitoring")
    WEnd

    ;~ Go back to main screen
    WinWait($CCHandle3)
    WinActivate($CCHandle3)
    WinWaitActive($CCHandle3, '', 18)
    Sleep(50)

    Send("{TAB 2}")

    Send("{ENTER}")

    ControlClick($CCHandle2, "&Cleaner", 1000)

    ;~ Clean up. Delete installer and close
    FileDelete('C:\ccsetup.exe')

WEnd

 

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...