Jump to content

Help with Conditional Statements


Recommended Posts

I'm in the process of creating a script that will automate the install of firefox that can be pushed out over a network. I'm doing this without using any mouse clicks because the settings for each computer can be very different. The problem I'm having is with conditional statements. I'm a complete newbie and I haven't found away to do this on the forums. What I need to do is write a statement that would basically say if the default browser window appears send the enter key and then close firefox, if it doesn't display or if firefox is already the default browser then firefox should just close. I need to do this because we don't know if everyone will have firefox already installed. If it's not installed already we will get the default browser message if it is then we won't. I have the code in to send the enter key when the default browser window appears however if that windows doesn't appear the script will get stuck and just remain in the task bar waiting for that window. If anyone has an idea on how I can go about doing this it would be greatly appreciated, thanks in advance for your time.

Link to comment
Share on other sites

i dont have firefox.... but this should do what you want

If FileExists(@ProgramFilesDir & "\firefox???\Firefox.exe????") Then

MsgBox(64, "* NOTE * ", "fire fox is already installed ", 5)

exit

endif

<{POST_SNAPBACK}>

Thanks for the reply but I don't think this will do exactly what I want. It needs to run silently and the same script needs to run weather they have firefox of not as it will be a method of updating to newer versions of firefox. Basically I need it to just do the job no matter what so I have to put in some conditional statements to make sure the script continues for both possible situations, updating or new install. Here's the script I have so far:

Run("C:\Documents and Settings\user\Desktop\Firefox Setup 1.0.4.exe")

WinWaitActive("Firefox Setup")

Send("!n")

WinWaitActive("Software License Agreement")

send("{up}")

send("!n")

WinWaitActive("Setup Type")

send("!n")

WinWaitActive("Select Components")

send("!n")

WinWaitActive("Install Complete")

send("{down}")

send("{space}")

send("{enter}")

WinWaitActive("Default Browser")

send("{enter}")

WinClose("University of Wisconsin-Milwaukee - Mozilla Firefox")

Thanks for the help guys.

Link to comment
Share on other sites

1 well, if this staement is true....

If FileExists(@ProgramFilesDir & "\firefox???\Firefox.exe????") Then

then you know firefox is installed... (and i am sure it will ask if you want it to be the default browser)

however you can check for the "opened browser" with

if winexist(internet explorer then run install.....ie Call(function)_

elseif winexist(firefox then. run update....

2 are you sure "they" are going to download it here?

Run("C:\Documents and Settings\user\Desktop\Firefox Setup 1.0.4.exe")

*EDIT*

if processexist(firefox.exe) then you know its the default

this help?

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

1 well, if this staement is true....

If FileExists(@ProgramFilesDir & "\firefox???\Firefox.exe????") Then

then you know firefox is installed... (and i am sure it will ask if you want it to be the default browser)

however you can check for the "opened browser" with

if winexist(internet explorer then run install.....ie Call(function)_

elseif winexist(firefox then. run update....

2 are you sure "they" are going to download it here?

Run("C:\Documents and Settings\user\Desktop\Firefox Setup 1.0.4.exe")

*EDIT*

if processexist(firefox.exe) then you know its the default

this help?

<{POST_SNAPBACK}>

No they won't have to download it there, infact they won't have to download it at all. I have that line of code in there for my testing purposes as I develope the script eventually that will all be included in the package we push out. The user won't have to do anything it's just going to be pushed out one evening and when they get back they'll have firefox updated and ready to use. Our main concern is that we have a way to update firefox, but it is possible that they never had it to begin with. I will play around with your recommendation looks like it should work would it be possible to just look for one window though such as

if winexist("Default Browser") then send("{enter}")

else WinClose("Mozilla Firefox")

If so could I throw an and in there so it's something like

if winexist("Default Browser") then send("{enter}") and WinClose("Mozilla Firefox")

else WinClose("Mozilla Firefox")

Thanks for all the help programming is not my strong area.

Link to comment
Share on other sites

Still having issues with this if anyone has an idea on what I can do to get the results I'm looking I'd greatly apriciate it. This is my first original script in autoit so I'm a complete newbie with this. Any assistance would be great.

Link to comment
Share on other sites

I personally prefer ControlSend() that way, if someone is playing with the computer, the commands to the install window still get to the install window. Also, if the correct homepage doesn't come up, it should send an email (make sure to change the settings at the bottom, I don't even know Wisconsin-Milwaukee's website) to whatever email address you specify. That functionality only works in some of the beta versions (I know most of the them, I don't remember a number, but .47 and higher for sure).

Hope that helps

Edit: Added the first line of code to see if Firefox is already current. If it isn't, or it doesn't exist (returns 0.0.0.0) then it will continue the installation program

If FileGetVersion(@ProgramFilesDir & "\Mozilla Firefox\Firefox.exe") >= "1.0.4.0" Then Exit

FileInstall("Firefox Setup 1.0.4.exe", @TempDir & "\Firefox Setup 1.0.4.exe")
Run(@TempDir & "\Firefox Setup 1.0.4.exe")
;;Wait for Setup Program to load
WinWaitActive("Firefox Setup")
ControlSend("Firefox Setup", "Welcome", 12325, "{ENTER}")

WinWaitActive("Software License Agreement")
ControlSend("Software License Agreement", "", 1081, "{SPACE}")
ControlSend("Software License Agreement", "", 12325, "{ENTER}")

WinWaitActive("Setup Type")
ControlSend("Setup Type", "", 12325, "{ENTER}")

WinWaitActive("Select Components")
ControlSend("Select Components", "", 12325, "{ENTER}")

WinWaitActive("Install Complete")
ControlSend("Install Conplete", "", 1091, "{SPACE}")
ControlSend("Install Conplete", "", "", "{ENTER}")

WinWaitActive("Default Browser")
ControlSend("Install Conplete", "", 12325, "{ENTER}")

If WinExists("University of Wisconsin-Milwauke - Mozilla Firefox") = 0 Then
;There was an error Send email to send an email
    
;guaranteed to work with 3.1.1.47 and later, works with *most* beta versions,
;i just forgot where the bug was fixed in beta :P
    SendEmail()
EndIf
ProcessClose("firefox.exe")
While FileExists(@TempDir & "\Firefox Setup 1.0.4.exe")
    FileDelete(@TempDir & "\Firefox Setup 1.0.4.exe")
WEnd

Func SendEmail()
    If @AutoItVersion >= "3.1.1.47" Then
        $objMessage = ObjCreate ("CDO.Message")
        With $objMessage
            .Subject = "Firefox Install Error"
            .Sender = "anonymousip@wisconsin.edu"
            .From = "anonymousip@wisconsin.edu"
            .To = "youremail@wisconsin.edu"
            .TextBody = @ComputerName & " (" & @IPAddress1 & ") did not successfully install Firefox.  It may just be the homepage setting, however."
        EndWith
        With $objMessage.Configuration.Fields
            .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.wisconsin.edu"
            .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1;set to 0 if no auth is necessary
            .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "john doe"
            .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "my password"
            .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
            .Update
        EndWith
        $objMessage.Send
    EndIf
EndFunc;==>SendEmail
Edited by MSLx Fanboy

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

Wow that helped out alot thanks. I didn't even know about controlsend actually. One thing I still want to do though is basically make a conditional statement for the default browser window. If fire say 1.03 is installed we still want to install 1.04 therefore we that box won't apear if that's the case I just want firefox to close. Would it look something like this then

If WinExists("Default Browser") = 1 Then

WinWaitActive("Default Browser")

ControlSend("Install Conplete", "", 12325, "{ENTER}"))

else WinClose("University of Wisconsin-Milwaukee - Mozilla Firefox")

EndIf

or am I totally off target here?

I personally prefer ControlSend() that way, if someone is playing with the computer, the commands to the install window still get to the install window.  Also, if the correct homepage doesn't come up, it should send an email (make sure to change the settings at the bottom, I don't even know Wisconsin-Milwaukee's website) to whatever email address you specify.  That functionality only works in some of the beta versions (I know most of the them, I don't remember a number, but .47 and higher for sure).

Hope that helps

Edit:  Added the first line of code to see if Firefox is already current.  If it isn't, or it doesn't exist (returns 0.0.0.0) then it will continue the installation program

If FileGetVersion(@ProgramFilesDir & "\Mozilla Firefox\Firefox.exe") >= "1.0.4.0" Then Exit

FileInstall("Firefox Setup 1.0.4.exe", @TempDir & "\Firefox Setup 1.0.4.exe")
Run(@TempDir & "\Firefox Setup 1.0.4.exe")
;;Wait for Setup Program to load
WinWaitActive("Firefox Setup")
ControlSend("Firefox Setup", "Welcome", 12325, "{ENTER}")

WinWaitActive("Software License Agreement")
ControlSend("Software License Agreement", "", 1081, "{SPACE}")
ControlSend("Software License Agreement", "", 12325, "{ENTER}")

WinWaitActive("Setup Type")
ControlSend("Setup Type", "", 12325, "{ENTER}")

WinWaitActive("Select Components")
ControlSend("Select Components", "", 12325, "{ENTER}")

WinWaitActive("Install Complete")
ControlSend("Install Conplete", "", 1091, "{SPACE}")
ControlSend("Install Conplete", "", "", "{ENTER}")

WinWaitActive("Default Browser")
ControlSend("Install Conplete", "", 12325, "{ENTER}")

If WinExists("University of Wisconsin-Milwauke - Mozilla Firefox") = 0 Then
;There was an error Send email to send an email
    
;guaranteed to work with 3.1.1.47 and later, works with *most* beta versions,
;i just forgot where the bug was fixed in beta :P
    SendEmail()
EndIf
ProcessClose("firefox.exe")
While FileExists(@TempDir & "\Firefox Setup 1.0.4.exe")
    FileDelete(@TempDir & "\Firefox Setup 1.0.4.exe")
WEnd

Func SendEmail()
    If @AutoItVersion >= "3.1.1.47" Then
        $objMessage = ObjCreate ("CDO.Message")
        With $objMessage
            .Subject = "Firefox Install Error"
            .Sender = "anonymousip@wisconsin.edu"
            .From = "anonymousip@wisconsin.edu"
            .To = "youremail@wisconsin.edu"
            .TextBody = @ComputerName & " (" & @IPAddress1 & ") did not successfully install Firefox.  It may just be the homepage setting, however."
        EndWith
        With $objMessage.Configuration.Fields
            .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.wisconsin.edu"
            .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1;set to 0 if no auth is necessary
            .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "john doe"
            .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "my password"
            .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
            .Update
        EndWith
        $objMessage.Send
    EndIf
EndFunc;==>SendEmail

<{POST_SNAPBACK}>

Link to comment
Share on other sites

You can set it via prefs.js in the user's profile directory. Give me a few minutes, i might be able to get a line of code or so to get that working

grrr...I've been working on this for a few minutes now (its 5:15pm right now)...and I don't have time to figure out why the second file handle is not working correctly. Also the last window in the installation program isn't receiving the {ENTER} key now. Someone want to take a look at this and tell me wtf I did wrong?

I have to head out to a Red Cross training event...sorry I couldn't be of more help to you right now :(

Edit: Oh, it might be the prefs variable I have in there, it must go to the only folder in the directory its held in, I just can't think of how to figure out the name of that sole folder :(

test.au3

Edited by MSLx Fanboy

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

So I take a look at it again, and realize that FileFindNextFile works with directories as well...

There are still a few bugs with it (it doesn't close the final install window, I can't figure it out, maybe its just my machine...)

Hope that helps you though

test.au3

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

Well so far nothing has worked for me so I'm back to my original code. Still having problems with one area and that's the last conditional statement everything else works great. My code is pasted below the part in red is where I'm having problems. For what ever reason I can't get firefox to be the active window. However even when I click on firefox it won't actually change focus to the default browser window to set the default browser. I had it working in the past however it isn't now any suggestions and what I can do would be very much appritiated.

Dim $iBlank = " "; Or other caracter

Dim $iEnter = @CR

Dim $iLine1 = "Please wait while maintenance is performed"

Dim $iLine2 = "This will take several minutes"

SplashTextOn(" I&MT", $iLine1 & $iEnter & $iBlank & $iLine2, 900, 600, -1, -1)

If ProcessExists("firefox.exe") then

ProcessClose("firefox.exe")

EndIf

Run("C:\Documents and Settings\tsbrice\Desktop\Firefox Setup 1.0.4.exe")

WinWaitActive("Firefox Setup")

Send("!n")

WinWaitActive("Software License Agreement")

send("{up}")

send("!n")

WinWaitActive("Setup Type")

send("!n")

WinWaitActive("Select Components")

send("!n")

WinWaitActive("Install Complete")

send("{down}")

send("{space}")

send("{enter}")

WinWaitActive("Mozilla Firefox")

Sleep(5000)

If WinExists("Default Browser") = 0 Then

WinActive("Default Browser")

send("{enter}")

else ProcessClose("firefox.exe")

EndIf

If ProcessExists("firefox.exe") then

ProcessClose("firefox.exe")

EndIf

Sleep(5000)

SplashOff()

#include <GUIConstants.au3>

GUICreate("I&MT", 200, 100)

GUICtrlCreateLabel("Thank you for your time!", 30, 10)

GUISetState(@SW_SHOW)

Sleep(2000)

Link to comment
Share on other sites

I take it "Default Browser" is not the actual window name and you are hoping to replace it.

To find the default browser I usually get this value from the registry.

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\https\shell\open\command

qq

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