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.
LVL 7
KnightsmanAsked:
Who is Participating?
 
Paul TomasiCommented:
At the start of your script, create an entry in your registry database under:

    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce

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.

0
 
QlemoBatchelor, 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.
0
 
matrixnzCommented:
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:

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

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

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:
[Program01]
Install=<Path to my Setup>\Setup.exe /switches

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Paul TomasiCommented:
Do you need your solution in batch file format or AutoIt format?
0
 
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.  

0
 
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...
0
 
Paul TomasiCommented:
.... I'm going to bed !!
0
 
KnightsmanAuthor Commented:
DIdn't mean to make you work good sir.  I appreciate the time you put into this.
0
 
matrixnzCommented:
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.

Cheers

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

Open in new window

0
 
KnightsmanAuthor Commented:
Thanks guys, sorry this took so long
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.