Jump to content

AutoIt - String Values

Satisfoxy

I've created a program that automates software installs locally and offline. This year, I wanted to clean my code and learn how to create string values instead of a separate script for every single thing. I've been staring at the AutoIt help file for about 6 hours now and everything I try doesn't work. If I could just see my one script work, I'm positive I can get the rest of them to do the same.
 

;Require admin so there are no file permission errors.
;2024
#RequireAdmin
#include <Process.au3>
#include <MsgBoxConstants.au3>

Local $reader64 = "Run(@ScriptDir & "\Adobe Reader\AcroRdrDCx642300620360_en_US.exe")

WinWait ("Adobe Acrobat Reader DC (Continuous) - Setup", "Adobe Acrobat is configured to install updates");Wait for the first window.
WinActivate ("Adobe Acrobat Reader DC (Continuous) - Setup", "Adobe Acrobat is configured to install updates");Activate the window.
ControlClick ("Adobe Acrobat Reader DC (Continuous) - Setup", "Adobe Acrobat is configured to install updates", "Button6");Click Install.

WinWait ("Adobe Acrobat Reader DC (Continuous) - Setup", "Setup has successfully installed");Wait for the second window.
WinActivate ("Adobe Acrobat Reader DC (Continuous) - Setup", "Setup has successfully installed");Activate the window.
ControlClick ("Adobe Acrobat Reader DC (Continuous) - Setup", "Setup has successfully installed", "Button2")"

Local $readerxp = Run(@ScriptDir & "\Adobe Reader\AdbeRdr11008_en_US.exe")

WinWait ("Adobe Reader XI (11.0.08) - Setup", "Ready to Install Adobe Reader");Wait for the first window.
WinActivate ("Adobe Reader XI (11.0.08) - Setup", "Ready to Install Adobe Reader");Activate the window.
ControlClick ("Adobe Reader XI (11.0.08) - Setup", "Ready to Install Adobe Reader", "Button1");Click next.

WinWait ("Adobe Reader XI (11.0.08) - Setup", "Keep your product up-to-date");Wait for the second window.
WinActivate ("Adobe Reader XI (11.0.08) - Setup", "Keep your product up-to-date");Activate the window.
ControlClick ("Adobe Reader XI (11.0.08) - Setup", "Keep your product up-to-date", "Button8");Do not check for updates.
Sleep(1500)
ControlClick ("Adobe Reader XI (11.0.08) - Setup", "Keep your product up-to-date", "Button1");Click install.

WinWait ("Adobe Reader XI (11.0.08) - Setup", "Setup Completed");Wait for the second window.
WinActivate ("Adobe Reader XI (11.0.08) - Setup", "Setup Completed");Activate the window.
ControlClick ("Adobe Reader XI (11.0.08) - Setup", "Setup Completed", "Button1"); Click finish.

if @OSArch = "X64" Then $reader64

elseIf @OSVersion = "WIN_XP" Then $readerxp

Sleep(2000)
EndIf

 

Thank you for reading.

 

♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥

My entire life is references to TV shows and Memes.

Dell OptiPlex GX1, Intel Pentium 3 @ 450MHz, 128MB PC133 RAM, Windows 98 Second Edition, Office 97' Professional

Link to comment
Share on other sites

Link to post
Share on other sites

I will preface this with: I have next to no experience with AutoIt, but lots with other scripting languages.

 

Minor (but catastrophic) issue, you've got an unclosed double quote at the start of the first string, and no quotes at all around the second string.

Edit: Not unclosed, just really long. Second one has no quotes though

 

The more relevant problem is you've got the entire control flow of your script wrong. You've placed all the install steps in the way of the main program execution. What your script does right now is it assigns the $reader64 variable, then it immediately starts waiting for the Acrobat Reader DC window to appear, and it never will because nothing got run.

 

Unless you tell it otherwise, the program gets executed top to bottom. It can't know that what you actually want it to do is skip to the end, run the right installer based on the OS (via trying to execute a string with an If... Then... block, which don't believe actually works), only go through the steps for the right installer, then quit.

 

Edit: I misunderstood how you were trying to do this, you were making great big multiline strings and trying to execute them. That would be a valid idea if If... Then... blocks could actually execute strings (and if readerxp had quotes around it), but I think functions are a much better alternative to executing strings, which doesn't appear to be easily possible in AutoIt.

 

You need to restructure your program so that the installation steps don't get in the way of the execution and explicitly separate the steps for each installer, and the way to do that is with functions.

 

I believe something like this would work:

;Require admin so there are no file permission errors.
;2024
#RequireAdmin
#include <Process.au3>
#include <MsgBoxConstants.au3>

If @OSArch = "X64" Then
    Reader64()
ElseIf @OSVersion = "WIN_XP" Then 
    ReaderXP()
EndIf

Func Reader64()
    Run(@ScriptDir & "\Adobe Reader\AcroRdrDCx642300620360_en_US.exe")
    
    WinWait ("Adobe Acrobat Reader DC (Continuous) - Setup", "Adobe Acrobat is configured to install updates");Wait for the first window.
    WinActivate ("Adobe Acrobat Reader DC (Continuous) - Setup", "Adobe Acrobat is configured to install updates");Activate the window.
    ControlClick ("Adobe Acrobat Reader DC (Continuous) - Setup", "Adobe Acrobat is configured to install updates", "Button6");Click Install.
    
    WinWait ("Adobe Acrobat Reader DC (Continuous) - Setup", "Setup has successfully installed");Wait for the second window.
    WinActivate ("Adobe Acrobat Reader DC (Continuous) - Setup", "Setup has successfully installed");Activate the window.
    ControlClick ("Adobe Acrobat Reader DC (Continuous) - Setup", "Setup has successfully installed", "Button2")
EndFunc

Func ReaderXP()
    Run(@ScriptDir & "\Adobe Reader\AdbeRdr11008_en_US.exe")
    
    WinWait ("Adobe Reader XI (11.0.08) - Setup", "Ready to Install Adobe Reader");Wait for the first window.
    WinActivate ("Adobe Reader XI (11.0.08) - Setup", "Ready to Install Adobe Reader");Activate the window.
    ControlClick ("Adobe Reader XI (11.0.08) - Setup", "Ready to Install Adobe Reader", "Button1");Click next.
    
    WinWait ("Adobe Reader XI (11.0.08) - Setup", "Keep your product up-to-date");Wait for the second window.
    WinActivate ("Adobe Reader XI (11.0.08) - Setup", "Keep your product up-to-date");Activate the window.
    ControlClick ("Adobe Reader XI (11.0.08) - Setup", "Keep your product up-to-date", "Button8");Do not check for updates.
    Sleep(1500)
    ControlClick ("Adobe Reader XI (11.0.08) - Setup", "Keep your product up-to-date", "Button1");Click install.
    
    WinWait ("Adobe Reader XI (11.0.08) - Setup", "Setup Completed");Wait for the second window.
    WinActivate ("Adobe Reader XI (11.0.08) - Setup", "Setup Completed");Activate the window.
    ControlClick ("Adobe Reader XI (11.0.08) - Setup", "Setup Completed", "Button1"); Click finish.
EndFunc
Edited by BobVonBob

¯\_(ツ)_/¯

 

 

Desktop:

Intel Core i7-11700K | Noctua NH-D15S chromax.black | ASUS ROG Strix Z590-E Gaming WiFi  | 32 GB G.SKILL TridentZ 3200 MHz | ASUS TUF Gaming RTX 3080 | 1TB Samsung 980 Pro M.2 PCIe 4.0 SSD | 2TB WD Blue M.2 SATA SSD | Seasonic Focus GX-850 Fractal Design Meshify C Windows 10 Pro

 

Laptop:

HP Omen 15 | AMD Ryzen 7 5800H | 16 GB 3200 MHz | Nvidia RTX 3060 | 1 TB WD Black PCIe 3.0 SSD | 512 GB Micron PCIe 3.0 SSD | Windows 11

Link to comment
Share on other sites

Link to post
Share on other sites

I will attempt this when I return to my workstation and will report back with results and if I had to change anything to get it working via AutoIt.

I am pretty basic when it comes to scripting, but flow control is not something the help file teaches.

However, even now -- thank you for helping me understand so far.

♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥

My entire life is references to TV shows and Memes.

Dell OptiPlex GX1, Intel Pentium 3 @ 450MHz, 128MB PC133 RAM, Windows 98 Second Edition, Office 97' Professional

Link to comment
Share on other sites

Link to post
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

×