Run a Cmd based on text file contents

Thanks for the help in advance

I'm running some cmds and autoit scripts, and I want to create a text file for the programs that need to restart the computer on occasion.  When the program calls for a restart, the cmd creats a text file that marks what program ran lasts, and on startup, I want the cmd line to run the next program based on the text file contents.  Pretty much, program 1 will only have the #1 in the text file.  

I'm still rather new to coding, and I have a good handle on it, and can read and learn with playing with stuff, but I cant seem to find any references to this, or if its possible.

Thanks again.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul TomasiCommented:
At the start of your script, create an entry in your registry database under:


It should be something like:

    AutoIt3.exe myscript.au3 parameter

The parameter can be a label for use with GOTO.

Update this registry entry for each command in the script or to point to when you want to restart the computer.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Good idea, Paul. The RunOnce entry will vanish after being executed. But I assume Knightsman needs more help, as the description of the current process is different.
Would require more information around the program requesting the restart, if you're running programs for instance in a sequence then that makes it easier.  I'm not sure why you require the CMD Scripts as AutoIT can handle the entire process, by using switches to your compiled executable (see example below).  You can also utilise Pauls idea for restarting but it does depend on the program requesting the restart.  In the examle below you would start the script by using the compiled AutoIT executable and switches i.e. MyAutoIT.exe -Switch01, alot will depend on how the program exits, you would probably try and get the script to restart rather than the program in case it closes the wrapper, anyway hope that gives you something to play with:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

If $CMDLINE[0] > 0 Then
  Switch $CMDLINE[1]
    Case '-Switch01'
      RegWrite('HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce', 'Switch02', 'REG_SZ', @ScriptDir & '\CompiledAutoIT.exe -Switch02')
    Case '-Switch02'
      RunWait(@ComSpec ' /c DosCommand.exe -switches')
      RegWrite('HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce', 'Switch03', 'REG_SZ', @ScriptDir & '\CompiledAutoIT.exe -Switch03')
    Case '-Switch03'

Open in new window

If you wish to create a text file then I'd recommend using an ini file, it's simple to write and you can use the internal AutoIT commands to reference them for example:

Write an Ini File
IniWrite('<Path to Ini File>\Filename.ini', 'Program01', 'Install', '<Path to my Setup>\Setup.exe /switches')

Open in new window

Read an Ini File
IniRead('<Path to Ini File>\Filename.ini', 'Program01', 'Install', 'Not Found')

Open in new window

The Filename.ini would be in the format:
Install=<Path to my Setup>\Setup.exe /switches

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Paul TomasiCommented:
Do you need your solution in batch file format or AutoIt format?
KnightsmanAuthor Commented:
Thanks everyone, going to play with this a little bit.  For now its going to be a sequence, probably the same, but will changed depending.  Its for antivirus scans, like SAS, malwarebytes, combofix, emsisoft, atf cleaner, ccleaner, etc.

The reason I want batch files with autoIT, is it seems to be easier to run the scripts no matter what the version of windows is.  Going to guess as I learn more about Autoit, ill learn to compensate for each OS.

the plan is to just start the next script in line after restart.  SAS needs restart, then move to malwarebytes.

I really like the idea of creating the startup in the reg.
matrixnz i dont fully understand exactly what your script is doing but going to try to learn it.  

Paul TomasiCommented:
It appears you may be better off doing the whole thing in a batch file...

I'll see if I can put something together for you in the next few moments...
Paul TomasiCommented:
.... I'm going to bed !!
KnightsmanAuthor Commented:
DIdn't mean to make you work good sir.  I appreciate the time you put into this.
AutoIT is compatible with all Windows OSs, however if the software has some dependencies then it's quite easy to accomodate with AutoIT for example, looking at the OSVersion and architecture especially with Windows 7 (see example below)

The code above is just an example basically you're creating an AutoIT Compiled executable which has switches this way you can include all your commands into one script and reference these by just calling them from a commandline.

One of the major pluses about AutoIT is that it also allows a custom Gui Interface.


If @OSVersion ='Win_XP' Then
ElseIf @OSVersion = 'Win_7' and @OSArch = 'x86' Then
  Run(...32 bit program...)
  Run(...64 bit program...)

Open in new window

KnightsmanAuthor Commented:
Thanks guys, sorry this took so long
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.