Saturday, June 15, 2013

FileInstall - Including Files in AutoIt Scripts

The FileInstall() function allows the inclusion of any file—such as an executable
or image file—in the compiled script executable. This is similar to #include, but
it dramatically increases the size of your compiled executable in most cases. This
is the syntax of the FileInstall() function:
FileInstall("sourcefile","destination" [,flag])
The flags for FileInstall() are optional. A flag of 0 tells the function not to overwrite
existing files. Use a flag of 1 if you would like to overwrite any existing files
the script may encounter. The source file cannot be a variable; it must be a string,
and it cannot contain wildcards.
Example 1 is an installation you can perform with the FileInstall() function that
extracts all installation files to the temp directory. When compiled, the entire installation
is a single executable.

Example 1. Using the FileInstall() Function
#NoTrayIcon
Opt("MustDeclareVars", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\Setup.exe", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\setup.ico", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\setup.ini", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\program.dll", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\readme.txt", 1)
Run(@TempDir & "\Setup.exe")
WinWait("Installation Wizard", "Welcome to the")
If Not WinActive("Installation Wizard", "Welcome to the") Then _
WinActivate("Installation Wizard", "Welcome to the")
WinWaitActive("Installation Wizard", "Welcome to the")
ControlClick("Installation Wizard", "", "Next")
WinWait("Installation Wizard", "Installation Complete")
If Not WinActive("Installation Wizard", "Installation Complete") Then _
WinActivate("Installation Wizard", "Installation Complete")
WinWaitActive("Installation Wizard", "Installation Complete")
ControlClick("Installation Wizard", "", "Finish")


In this example, FileInstall() copies five files to the temp directory, then the Run
() command runs Setup.exe. The program then waits for the installation wizard to
appear using WinWait() and makes it active using WinActivate() before clicking
Next with ControlClick() and then Finish with ControlClick() to complete the
installation.

3 comments: