Sign in to follow this  
Followers 0
BrandonW

Script not allowing batch file to complete

17 posts in this topic

I was turned onto Autoit by our SysAdmin and have never been much into programming, but this seems to not be extremely complicated. Here is what I am trying to do:

Normally, we have a folder on our storage server that we copy over to the local drive. In that folder, we run a batch file that installs our software then closes. I run a autologon reghack, then reboot the computer.

What I want is to double-click on *.exe that creates a folder on the desktop, copies the contents of the install folder from the server to the local folder. Then, execute the batch file and when it is done, show a message basically saying "Done" and then reboot automatically after 30 seconds or so. I'm not worried about running the reghack right now.

The script below is what I have with shutdown disabled for now. It will execute the batch file, but close it after a couple seconds and give the Done message. This batch file takes anywhere from 10-20 seconds depending on the PC specs.

What am I missing/doing wrong here?

; Prompt the user to run the script
$answer = MsgBox(4, "QS Install Process", "This script will copy the QS folder to the desktop and run install.cmd.  Run?")

; Check the user's answer to the prompt
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(0, "AutoIt", "OK.  Bye!")
    Exit
EndIf

; Creates a directory on the local desktop called QS Install
DirCreate("C:\Documents and Settings\user\Desktop\QS Install")

; Copies the contents of the qs install folder on server to the QS Install folder
DirCopy("\\server\install\qs install folder", "C:\Documents and Settings\user\Desktop\QS Install", 1)

; Runs Install.bat and waits to finish before continuing script
Run("C:\Documents and Settings\user\Desktop\QS Install\Install.bat")
WinWaitClose("C:\WINDOWS\system32\cmd.exe")

; Script completed. Wait 30 seconds then force reboot
MsgBox(4096, "Done", "Test 12", 30)

;Shutdown(6);Reboot

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

First, use the RunWait function to replace run and winwaitclose.

Edited by Inverted

Share this post


Link to post
Share on other sites

I tried RunWait and it did the same thing. I read somewhere on here that it could be some issue with the command prompt.

Share this post


Link to post
Share on other sites

Does that mean that the Batchfile is done before the program shelled by the batch file finishes?

You could try to use the COmspec to shell the batch file, but else we need more info what the batchfile is doing.

RunWait(@comspec ' /c "C:\Documents and Settings\user\Desktop\QS Install\Install.bat"')


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

The batch file is executing a couple reghacks, settings attributes on ntuser.dat, then copying a couple folders from another server, then executing an msi quietly.

It doesn't even get to the MSI.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Are you sure the batch itself works properly (when launched from that location ?)

Insert some pauses in the batch to debug the problem

Edited by Inverted

Share this post


Link to post
Share on other sites

Without a doubt. I ran it from the newly created folder and it works like a charm.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Are you sure the batch itself works properly (when launched from that location ?)

Insert some pauses in the batch to debug the problem

Ok .. inserted a few pauses. Inserted one right before the msi ... I press enter and the script closes. Could the issue somehow be running it quietly? (Like I said, scripting isn't my thing .. I'm swinging in the dark here). Like I said .. it runs fine when I execute it by itself.

Edited by BrandonW

Share this post


Link to post
Share on other sites

Did you try the RunWait() with @Comspec?

One other thing to try is to use /K to see whats happening:

RunWait(@comspec ' /k "C:\Documents and Settings\user\Desktop\QS Install\Install.bat"')


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Jos: I did use the @comspec and received a "Line -1: Error in expression", so I added & and I'm back to my previous issue with it closing at the msi.

RunWait(@comspec & ' /c "C:\Documents and Settings\user\Desktop\QS Install\Install.bat"')

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I think I know why. The working directory is wrong. Try RunWait and set the Working directory to the same folder as the batch. Post the important lines of your autoit script also.

Or try ShellExecuteWait if that doesn't work. Also try the @SW_MAXIMIZE and $RUN_CREATE_NEW_CONSOLE flags to see what's going on.

Edited by Inverted

Share this post


Link to post
Share on other sites

Interesting ...

'blah.msi' is not recognized as an internal or external command, operable program or batch file.

Just to verify again, I ran the batch file immediately after getting that message.

I think I just had a lightbulb click on. Ok ... so I moved by *.exe INTO the folder that is created with the script. Ran it and everything worked fine. So I'm guessing this is a dumb move on my part by not defining the paths better?

Share this post


Link to post
Share on other sites

I think I know why. The working directory is wrong. Try RunWait and set the Working directory to the same folder as the batch. Post the important lines of your autoit script also.

Or try ShellExecuteWait if that doesn't work. Also try the @SW_MAXIMIZE and $RUN_CREATE_NEW_CONSOLE flags to see what's going on.

Ah you beat me to it.

Share this post


Link to post
Share on other sites

Jos: I did use the @comspec and received a "Line -1: Error in expression", so I added & and I'm back to my previous issue with it closing at the msi.

RunWait(@comspec & ' /c "C:\Documents and Settings\user\Desktop\QS Install\Install.bat"')
Yea right ... needed that & in there. :D

OK, so the batchfile shell an MSI after which it directly closes. I have seen that before and solved that by shelling the MSI using MSIEXEC.exe. Something like:

msiexec /i "Name-of-msi.msi"


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Woohoo! Got it done!

Thanks for the help guys and putting up with yet another n00b.

RunWait("C:\Documents and Settings\user\Desktop\QS Install\Install.bat", "C:\Documents and Settings\user\Desktop\QS Install")

Share this post


Link to post
Share on other sites

Don't use hardcoded paths like that, check the help file for the directory macros, so your script runs on all win installations.

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