Sign in to follow this  
Followers 0
GeekOrGuru

Help -- Debug Script

9 posts in this topic

OK...I'm a noob and still learning so please bear with me. I'm trying to learn AutoIt to deploy software across our network. I think I'm getting a basic understanding and making progress, but I've got a couple of hangups I can't figure out!

The script below has (2) problems:

1) Under the "Copy Installation Files" region...the script will hang up. If I cancel it and rerun it proceeds as expected. Why is it not copying the files on the first run?

2) Under the "Cleanup" region...I cannot get it to remove the "TEMP" directory regardless of what I try.

PLEASE HELP!

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=..\..\..\..\..\public\Downloads\BidX\5.9a\BidX_59a.exe
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Run_Obfuscator=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#region --- Installation Script ---

    #region --- Variables ---
    ; This section contains "Variables" which are utilized or called upon throughout the script.
    Dim $sDomain, $sUserName, $sPassword, $sApp, $sAppPath, $sLogFilesPath, $sLogFilesDirectory, $sVersion, $sTemp
    $sDomain = "DOMAIN"
    $sUserName = "USERNAME"
    $sPassword = "PASSWORD"
    $sApp = "setup.exe"
    $sAppPath = "\\FILE01\Public\Downloads\BidX\"
    $sLogFilesPath = "\\FILE01\Hutchens Storage\Office\Computers\Log Files\Application Installations\"
    $sLogFilesDirectory = "BidX\"
    $sVersion = "5.9a\"
    $sTemp = ("C:\TEMP\" & $sLogFilesDirectory & $sVersion)
    #endregion --- Variables ---

    #region --- System Check ---
    ; This section checks to see if the application is already installed on the local computer.
    ; If it is it verifies the version and installation log file; if a previous version is installed
    ; on the local computer, it uninstalls it and reinstalls the current version. If it is not installed,
    ; then it installs it.
    If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Info Tech Inc.\Expedite Bid\5.9a", "Version") = "5.9a" Then
            Call("_LogFile")
        ElseIf FileExists("C:\Program Files\Expedite") Or FileExists("C:\Expedite") Then
            Call("_Uninstall")
        Else
            Call("_Install")
    EndIf
    #endregion --- System Check ---

    #region --- Uninstall ---
    ; This section searches for previous installations and if present removes them.
    Func _Uninstall()
        If FileExists("C:\Program Files\Expedite") Then
            DirRemove("C:\Program Files\Expedite", 1)
        EndIf

        If FileExists("C:\Expedite") Then
            DirRemove("C:\Expedite", 1)
        EndIf

        If FileExists("C:\Documents and Settings\All Users\Start Menu\Programs\Expedite") Then
            DirRemove("C:\Documents and Settings\All Users\Start Menu\Programs\Expedite", 1)
        EndIf
    EndFunc
    #endregion --- Uninstall ---

    #region --- Installation Routine ---

        #region --- Copy Installation Files ---
        Func _Install()
            If FileExists($sTemp & $sApp) Then
                    Call("_Setup")
                Else
                    FileCopy($sAppPath & $sVersion & $sApp, $sTemp, 9)
                EndIf
        EndFunc
        #endregion --- Copy Installation Files

        #region --- Setup Function ---
        Func _Setup($title,$text,$timeout=0)
            WinWait($title,$text,$timeout)
            If Not WinActive($title,$text) Then WinActivate($title,$text)
            WinWaitActive($title,$text,$timeout)
        EndFunc
        #endregion --- Setup Function ---

        #region --- Setup Function Options ---
        Opt("WinWaitDelay",100)
        Opt("WinDetectHiddenText",1)
        Opt("MouseCoordMode",0)
        #endregion --- Setup Function Options ---

        #region --- Application Setup Routine ---
        RunAs($sUserName, $sDomain, $sPassword, 0, $sTemp & $sApp)
        _Setup("Expedite Bid 5.9a Setup", "The InstallShield Wi")
            Send("{ENTER}")
        _Setup("Expedite Bid 5.9a Setup", "Please read the foll")
            Send("{ENTER}")
        _Setup("Expedite Bid 5.9a Setup", "Setup will install E")
            Send("{TAB}{TAB}{ENTER}")
        _Setup("Choose Folder", "Please select the in")
            Send("C:\Program Files\Expedite\5.9a{ENTER}")
        _Setup("Expedite Bid 5.9a Setup", "Setup will install E")
            Send("{ENTER}")
        _Setup("Expedite Bid 5.9a Setup", "Setup will add progr")
            Send("{ENTER}")
        _Setup("Expedite Bid 5.9a Setup", "Setup has completed ")
            Send("{SPACE}{TAB}{ENTER}")
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Info Tech Inc.\Expedite Bid\5.9a", "Version", "REG_SZ", "5.9a")
        #endregion --- Application Setup Routine ---

        #region --- Cleanup ---
        FileDelete("C:\Documents and Settings\All Users\Desktop\Expedite*.*")
        DirRemove($sTemp, 1)
        #endregion --- Cleanup ---

    Call("_LogFile")

    #endregion --- Installation Routine ---

    #region --- Logging ---
    ; This section checks to see if a log file already exists.  If it already exists it exits the script;
    ; if it does not already exist then it creates a log file in the network installation directory.
    Func _LogFile()
        If FileExists($sLogFilesPath & $sLogFilesDirectory & $sVersion & @ComputerName & ".txt") Then
            Exit
        Else
            FileWriteLine($sLogFilesPath & $sLogFilesDirectory & $sVersion & @ComputerName & ".txt", $sLogFilesDirectory & $sVersion & " Successfully Installed")
            FileWriteLine($sLogFilesPath & $sLogFilesDirectory & $sVersion & @ComputerName & ".txt", "")
            FileWriteLine($sLogFilesPath & $sLogFilesDirectory & $sVersion & @ComputerName & ".txt", "Computer Name:    " & @ComputerName)
            FileWriteLine($sLogFilesPath & $sLogFilesDirectory & $sVersion & @ComputerName & ".txt", "User Name:    " & @UserName)
            FileWriteLine($sLogFilesPath & $sLogFilesDirectory & $sVersion & @ComputerName & ".txt", "Date:     " & @MON & "/" & @MDAY & "/" & @YEAR)
            FileWriteLine($sLogFilesPath & $sLogFilesDirectory & $sVersion & @ComputerName & ".txt", "Time:     " & @HOUR & ":" & @MIN)
        EndIf
    Exit
    EndFunc
    #endregion --- Logging ---

#endregion --- Installation Script ---

And...if there are more efficient ways of doing things...please let me know. I'm always willing to try new things and learn something new.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Several errors ! Posted Image

.your Call("_Setup") have no parameters to send to your Func _Setup($title,$text,$timeout=0)

.a winwait with $timeout=0 is useless

.Syntax of your cleanup FileDelete is wrong, it must be FileDelete( "C:\Documents and Settings\All Users\Desktop\Expedite\*.tmp" ) like in the help file

.you can use Macros instead of "C:\Program Files\...

Edited by wakillon

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

Share this post


Link to post
Share on other sites

Wakillon,

Thanks for the input...

.your Call("_Setup") have no parameters to send to your Func _Setup($title,$text,$timeout=0)

I don't understand, my other functions are working properly and are set up just the same?

.a winwait with $timeout=0 is useless

This is the default output from the "Recorder".

.Syntax of your cleanup FileDelete is wrong, it must be FileDelete( "C:\Documents and Settings\All Users\Desktop\Expedite\*.tmp" ) like in the help file

This FileDelete is working as expected...it's the DirRemove right beneath it that is not, yet my other DirRemove calls are working just fine?

.you can use Macros instead of "C:\Program Files\...

My test box does not have System Variables expressed, thus I cannot test with the Macros.

So now what?

Share this post


Link to post
Share on other sites

Wakillon,

Thanks for the input...

I don't understand, my other functions are working properly and are set up just the same?

This is the default output from the "Recorder".

This FileDelete is working as expected...it's the DirRemove right beneath it that is not, yet my other DirRemove calls are working just fine?

My test box does not have System Variables expressed, thus I cannot test with the Macros.

So now what?

other functions are working properly because they have no parameters

$timeout=0 want to say it doesn't wait, so change for $timeout=5

I can't test your script but see if your condition statement for launch your _uninstall function is good

put a consolewrite ( '_uninstall ' & @Crlf ) at the begining of this function, you will see if it is launched...


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

Share this post


Link to post
Share on other sites

@wakillon

Setting Timeout to 0 seem to be infinite, not instant. Try this and you'll see:

WinWait("dfkdfkdkjfdkj", "", 0)

My test box does not have System Variables expressed, thus I cannot test with the Macros.

Are you saying that this:

MsgBox(0, "", "@ProgramFilesDir" & " = " & @ProgramFilesDir)

returns nothing?

:)

Share this post


Link to post
Share on other sites

@wakillon

Setting Timeout to 0 seem to be infinite, not instant. Try this and you'll see:

@AdmiralAlkex

you're right, I have yet seen no reference to this, in the winwait help part !

Remarks

None.

This should be added in remarks ! Posted Image


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

Share this post


Link to post
Share on other sites

Thanks everyone! Think I've made some major headway as I now have two scripts successfully running.

I changed my functions as suggested. For the one I set up the parameters, for all of them I removed the "Call". I don't understand why "Call" is in the help file though if it is a bad thing to do?

As far as the files/directories being removed...there were a couple of problems. On one of them it was a permissions issue so I added RunAs and on the other it was being held in the processes so I added ProcessWaitClose.

And re: the Macros...I had previously instead tried to utilize System or Environment Variables with no luck. But I did change things over to utilize the Macros now as well...basically figuring out that AutoIt does not utilize "Environment Variables" in the DOS sense of speaking, but rather has a way of calling upon those variables through the built in Macros.

Wahlah!

There are still basic questions I have, but I guess it just take time. It's mainly learning the way AutoIt thinks vs other scripting languages.

Share this post


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
Sign in to follow this  
Followers 0