Sign in to follow this  
Followers 0
mrrlg

Script Running Twice

7 posts in this topic

I am trying to run the following script from the user's desktop. When I double click on it, it will launch the script, and then launch it again. I have no idea why. I need to move the existing directory and then execute the setup of the new program from a network share.

The enter commands are my attempt to automate the installation process.

$__msgbox = MsgBox ( 4, 'AutoIt', 'This Script will install the Latest Version of Passport for Windows. Do you want to Continue?' )

if NOT ( $__msgbox = 7 ) then

BlockInput ( 1 )

DirMove ("C:\program files\oda\passport", "C:\test")

Run ( '\\passport\mistest\pfw235\setup.exe' )

Sleep ( 4000 )

Send ("{enter}")

Sleep ( 2000 )

Send ("{enter}")

Sleep ( 2000 )

Send ("{enter}")

Sleep ( 2000 )

Send ("{enter}")

Sleep ( 2000 )

Send ("{enter}")

Sleep (60000)

Send ("{enter}")

Sleep ( 10000 )

EXIT

Share this post


Link to post
Share on other sites



I can only guess but maybe you're starting it again becuase you're sending an enter while the setup is not the active window?

I also suggest to use ControlSend if you need to send keys or even better try to use ControlClick to simulate the clicking of a button. The AutoIt Window Spy can tell you which parameters you need to pass to the ControlClick/Send commands.

For example if the spy shows you, that the last control under the mouse (while you're on the button you want to click) is "Class: Button1" you could try

ControlClick("Microsoft Passport Setup", "", "Button1")

(change the window title to the one the AutoIt Window Spy is showing)

If you're able to use only ControlSend/Click there's no need for BlockInput(1), too.

BTW: You should check if the DirMove was successfull:

If not DirMove("C:\program files\oda\passport", "C:\test") Then
MsgBox(4096, "Cannot Move Directory", "The directory could not be moved. Check if a program is still running from this directory")
Exit(1)
EndIf
[continue with your normal script here]

Share this post


Link to post
Share on other sites

I'd suggest that instead of using sleeps you use winwaitactive or winwait along with controlsend and controlclick, or somesuch... it's much more relaible than just guessing that it'll take 4 seconds for the setup to load... and the keys won't fire off too early on a slow PC, or waste time on a fast machine...


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

Thanks for answering so quickly, the if not statement works, but now the script hangs at the first active window "Welcome" that requires a mouse click. I would like to completely automate this process. Should there be a space between the quotation marks?

$__msgbox = MsgBox ( 4, 'AutoIt', 'This Script will install the Latest Version of Passport for Windows. Do you want to Continue?' )

if NOT ( $__msgbox = 7 ) then

BlockInput ( 0 )

If not DirMove("C:\program files\oda\passport", "C:\test") Then

MsgBox(4096, "Cannot Move Directory", "The directory could not be moved. Check if a program is still running from this directory")

Exit(1)

Endif

BlockInput (1)

Run ( '\\passport\mistest\pfw235\setup.exe' )

ControlClick("Welcome","","Button 1")

ControlClick("Software License Agreement", "", "Button 2")

ControlClick("Choose Destination Location", "", "Button 1")

ControlClick("Setup Type", "", "Button 5")

ControlClick("Select Program Folder", "", "Button 2")

ControlClick("Setup Complete", "", "Button 4")

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I ran it through Tidy in SciTE, and added an else and exit to the end... just to be anal... I suggest you add winwaits after each controlclick to wait for the next window to pop up... I did it for after the first controlclick to give you the idea:

$__msgbox = MsgBox ( 4, 'AutoIt', 'This Script will install the Latest Version of Passport for Windows. Do you want to Continue?' )
if NOT ( $__msgbox = 7 ) then
   BlockInput ( 0 )
   If not DirMove("C:\program files\oda\passport", "C:\test") Then 
      MsgBox(4096, "Cannot Move Directory", "The directory could not be moved. Check if a program is still running from this directory")
      Exit(1)
   Endif
   BlockInput (1)
   
   Run ( '\\passport\mistest\pfw235\setup.exe' )
   ControlClick("Welcome","","Button 1")
   Winwait("Software License Agreement")
   ControlClick("Software License Agreement", "", "Button 2")
   ControlClick("Choose Destination Location", "", "Button 1")
   ControlClick("Setup Type", "", "Button 5")
   ControlClick("Select Program Folder", "", "Button 2")
   ControlClick("Setup Complete", "", "Button 4")
Else
   Exit
EndIf

edit: fixed the winwait to wait for what should be the right window...

Edited by emmanuel

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

I did as you suggested and now it freezes at the "Welcome" Window and I have to kill the script through task manager. I don't understand why the controlclick command doesn't execute automatically.

$__msgbox = MsgBox ( 4, 'AOOA MIS Dept', 'This Script will install the Latest Version of Passport for Windows. Do you want to Continue?' )

if NOT ( $__msgbox = 7 ) then

BlockInput ( 0 )

If not DirMove("C:\program files\oda\passport", "C:\test") Then

MsgBox(4096, "Cannot Move Directory", "The directory could not be moved. Check if a program is still running from this directory")

Exit(1)

Endif

BlockInput (1)

Run ( '\\passport\mistest\pfw235\setup.exe' )

ControlClick("Welcome", "","Button1")

WinWait("Software License Agreement")

ControlClick("Software License Agreement", "", "Button2")

WinWait("Choose Destination Location")

ControlClick("Choose Destination Location", "", "Button1")

WinWait("Setup Type")

ControlClick("Setup Type", "", "Button5")

WinWait("Select Program Folder")

ControlClick("Select Program Folder", "", "Button2")

WinWait("Setup Complete")

ControlClick("Setup Complete", "", "Button4")

Else

EXIT

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The problem is here:

Run ( '\\passport\mistest\pfw235\setup.exe' )
ControlClick("Welcome", "","Button1")

You're telling AutoIt to start setup.exe and then try to click on the button. But AutoIt will do this within maybe 5 milliseconds and the window wont have opened yet.

Just tell AutoIt to wait for the window before you're trying to click:

Run ( '\\passport\mistest\pfw235\setup.exe' )
WinWait("Welcome")
ControlClick("Welcome", "","Button1")
Edited by sugi

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