Jump to content

runwait() with an autorun.inf


Recommended Posts

Hi!

I made a script to execute the program inside an autorun of an ISO decompress folder. I mapped the folder with Windows command "subst x: path". I extract the program to run from the autorun. Execute the program and remove the map with the command "subst x: /d".

My problem is when I call the program using runwait(), the autorun start the program but this program call an another the program and close, so I'm unable to wait the script and my map is remove during the process of the program.

Anyone have an idea? I tried Winwait() and processwait() without success!

best regards

Edited by theflamme99
Link to comment
Share on other sites

It depends on what process you are running and waiting on. If the command you are waiting on is "subst", then once it is finished, which is not a very long time, the waiting is over and it is no to the next line in the script. If I understand you situation, you can try

RunWait('subst x: "' & $Path & '"')
Do
    Sleep(10)
Until FileExists('X:')
FileCopy('My Other Program.exe', 'X:\', 1)
$PID = Run('X:\My Other Program.exe')
ProcessWait($PID)
While ProcessExists($PID)
    Sleep(10)
Wend

Link to comment
Share on other sites

Hi,

I'm not waiting on the subst command but for the program in the autorun. The problem is this program start an another one so the pid of the run of the first program is not there anymore after lauching the child.

I made the tests with notepas and everything work fine because notepas doesn't start an another program.

Hope this is clearer ans thanks for your answer,

best regards,

Link to comment
Share on other sites

If you use ProcessExists with the program name, you won't need the PID. In Varian's code above change the ProcessExists($PID) to ProcessExists("<ProgramName>") where program name is the name of the program you're waiting to end. You would probably have to do the same in the ProcessWait command in the line before it as well so that it gives the program time to start before the script ends itself.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

That is pretty much what the code that I posted should solve. The code I posted is for your Autorun.exe file (aka Main Script). It should:

  • "map" a drive (not really important if it really does this or not, but it makes sense to me that it would, since it's main job is to copy files to X:\ and then launch those scripts).
RunWait('subst x: "' & $Path & '"')
Do
    Sleep(10)
Until FileExists('X:')
FileCopy('My Other Program.exe', 'X:\', 1)

  • Run one of those programs and wait for that program to close, itself inherently remaining open
$PID = Run('X:\My Other Program.exe')
ProcessWait($PID)
While ProcessExists($PID)
    Sleep(10)
Wend

  • Repeat for other programs that it has copied with the above code
By using this template, you can insure that your Main Script "Autorun.exe" will remain open for duration of your installation

EDIT: Maybe post relevant code of your Main script..if I am way off with the logic or structure of what you are trying to do, please explain further

Edited by Varian
Link to comment
Share on other sites

If you use ProcessExists with the program name, you won't need the PID. In Varian's code above change the ProcessExists($PID) to ProcessExists("<ProgramName>") where program name is the name of the program you're waiting to end. You would probably have to do the same in the ProcessWait command in the line before it as well so that it gives the program time to start before the script ends itself.

I am sure you know this, but for the OP and others that may not, using the Process Name only can be increasingly inaccurate. With more programs becoming multi-threading, relying on only the name of a Process can be hit-or-miss. Try closing "iexplore.exe" by process name and you'll likely see what I mean. Or even worse, try closing "chrome.exe" by process name. Chrome uses a separate thread for each of it's extensions & tabs, so you may (like me), have 10+ chrome.exe processes open at any time.

In short, it's better practice to use the PID return, especially because your script spawns it. I liken it to explicitly declaring variables..when things are simple, it's not so hard to debug irregularities, but as you develop more complex scripts, it becomes increasingly difficult to re-engineer your work.

EDIT:Can dyslexia develop with age??? I am really starting to have some issues with my typing.

Edited by Varian
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...