Jump to content

Automatically execute latest version of a program


Go to solution Solved by Nine,

Recommended Posts

Hello all,

I searched for this or a similar topic but could not find anything. I am quite new to AutoIT, so if I searched in a wrong way please redirect me.

We have installed different versions of the same application. The decision about the version is just by its folder.

f.e. 

  • C:\Software\Program 2.3\app\windows\program.exe
  • C:\Software\Program 2.8\app\windows\program.exe
  • C:\Software\Program 4.3\app\windows\program.exe

The .exe itself is always in the same directory inside the version folder and has always the same name.

I am looking for a possibility to automatically start the latest version of the program.exe application. Right now I use "Run" together with the path. If a new version of the program.exe is installed I have to manually adapt my AutoIt script which becomes annoying after some time.

My idea would be that AutoIt looks for the highest Program version number (=latest version) in the C:\Software\ folder and executes the program.exe.

Is this possible using AutoIt? If not - another option, if possible, would be to display all installed folders (Versions) over a GUI at the beginning of the script and the user has to select the latest one manually. 

Thanks in advice :) 

Link to comment
Share on other sites

You could read the directories into an array, parse the strings in a loop to find the highest program # value, and then execute the exe in that directory.  Another idea is to use the date of the newest folder in the directory containing all these versions.  The newest date is the one you should run.  The below example uses an array with the directories which you can get with _FileListToArray.  I just hard coded them to show an example of parsing.

#include <String.au3>
#include <Array.au3>
global $dirs[3]=["C:\Software\Program 2.3\app\windows\program.exe","C:\Software\Program 2.8\app\windows\program.exe","C:\Software\Program 4.3\app\windows\program.exe"] ; create array with all the dirs - replace this with a function

for $a=0 to ubound($dirs)-1  ; loop through the array
   global $finder=_StringBetween($dirs[$a],"C:\Software\Program ","\app\windows\program.exe") ; find the version and isolate
   if @error then ; check for errors
      MsgBox("","error",@error)
   EndIf
   _ArrayDisplay($finder) ; display result to screen
Next

P.S. Yes, you can display the folders - but if you can display the folders you already have the strings to work with to determine the latest version 😉

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

Assuming the installation directories are as you've stated, using _FileListToArrayRec with $FLTAR_SORT should result in the last item been the latest version.

#include <Array.au3>
#include <File.au3>

Global $g_sDir = 'C:\Software'
Global $g_aFolders
Global $g_sLastFolder

$g_aFolders = _FileListToArrayRec($g_sDir, Default, $FLTAR_FOLDERS, Default, $FLTAR_SORT, $FLTAR_FULLPATH)
If @ERROR Then
    ConsoleWrite('ERROR: _FileListToArrayRec' & @CRLF)
    Exit
EndIf

$g_sLastFolder = $g_aFolders[$g_aFolders[0]]

ConsoleWrite('Running: "' & $g_sLastFolder & '\app\windows\program.exe"')

Run($g_sLastFolder & '\app\windows\program.exe')

Edit: This would only work up until version 9.9. 😢

Edited by Luke94
Link to comment
Share on other sites

  • Solution

Assuming that the versioning is only based on 2 parts (xx.xx) :

#include <File.au3>

Const $sRoot = "C:\Apps\Temp"

Local $aFolders = _FileListToArrayRec($sRoot, "Software*", $FLTAR_FOLDERS, Default, Default, $FLTAR_FULLPATH)

_ArrayDisplay($aFolders)

Local $aVersion, $iFirst, $iLast, $iHighest

For $i = 1 to $aFolders[0]
  $aVersion = StringRegExp($aFolders[$i], "Software (\d*).(\d*)", 1)
  If Number($aVersion[0]) > $iFirst Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) > $iLast) Then
    $iFirst = Number($aVersion[0])
    $iLast = Number($aVersion[1])
    $iHighest = $i
  EndIf
Next

MsgBox(0, $iHighest, $aFolders[$iHighest])
Run($aFolders[$iHighest] & "\app\windows\program.exe")

 

Edited by Nine
Link to comment
Share on other sites

1 hour ago, Luke94 said:

Assuming the installation directories are as you've stated, using _FileListToArrayRec with $FLTAR_SORT should result in the last item been the latest version.

#include <Array.au3>
#include <File.au3>

Global $g_sDir = 'C:\Software'
Global $g_aFolders
Global $g_sLastFolder

$g_aFolders = _FileListToArrayRec($g_sDir, Default, $FLTAR_FOLDERS, Default, $FLTAR_SORT, $FLTAR_FULLPATH)
If @ERROR Then
    ConsoleWrite('ERROR: _FileListToArrayRec' & @CRLF)
    Exit
EndIf

$g_sLastFolder = $g_aFolders[$g_aFolders[0]]

ConsoleWrite('Running: "' & $g_sLastFolder & '\app\windows\program.exe"')

Run($g_sLastFolder & '\app\windows\program.exe')

Edit: This would only work up until version 9.9. 😢

Thanks for that solution - works fine but the problem is I have to go beyond version 10.

Link to comment
Share on other sites

1 hour ago, Nine said:

Assuming that the versioning is only based on 2 parts (xx.xx) :

#include <File.au3>

Const $sRoot = "C:\Apps\Temp"

Local $aFolders = _FileListToArrayRec($sRoot, "Software*", $FLTAR_FOLDERS, Default, Default, $FLTAR_FULLPATH)

_ArrayDisplay($aFolders)

Local $aVersion, $iFirst, $iLast, $iHighest

For $i = 1 to $aFolders[0]
  $aVersion = StringRegExp($aFolders[$i], "Software (\d*).(\d*)", 1)
  If Number($aVersion[0]) > $iFirst Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) > $iLast) Then
    $iFirst = Number($aVersion[0])
    $iLast = Number($aVersion[1])
    $iHighest = $i
  EndIf
Next

MsgBox(0, $iHighest, $aFolders[$iHighest])
Run($aFolders[$iHighest] & "\app\windows\program.exe")

 

I am just trying to edit your solution to 3 parts (xx.xx.xx) but I am a bit brainfucked by the and/or connections right now :(

Do you have a quick solution for 3 parts?

Link to comment
Share on other sites

#include <File.au3>

Const $sRoot = "C:\Apps\Temp"

Local $aFolders = _FileListToArrayRec($sRoot, "Software*", $FLTAR_FOLDERS, Default, Default, $FLTAR_FULLPATH)

_ArrayDisplay($aFolders)

Local $aVersion, $iFirst, $iMid, $iLast, $iHighest

For $i = 1 to $aFolders[0]
  $aVersion = StringRegExp($aFolders[$i], "Software (\d*).(\d*).(\d*)", 1)
  If Number($aVersion[0]) > $iFirst Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) > $iMid And Number($aVersion[2]) > $iLast) Then
    $iFirst = Number($aVersion[0])
    $iMid = Number($aVersion[1])
    $iLast = Number($aVersion[2])
    $iHighest = $i
  EndIf
Next

MsgBox(0, $iHighest, $aFolders[$iHighest])
Run($aFolders[$iHighest] & "\app\windows\program.exe")

Credits to @Nine

Link to comment
Share on other sites

9 minutes ago, Luke94 said:
#include <File.au3>

Const $sRoot = "C:\Apps\Temp"

Local $aFolders = _FileListToArrayRec($sRoot, "Software*", $FLTAR_FOLDERS, Default, Default, $FLTAR_FULLPATH)

_ArrayDisplay($aFolders)

Local $aVersion, $iFirst, $iMid, $iLast, $iHighest

For $i = 1 to $aFolders[0]
  $aVersion = StringRegExp($aFolders[$i], "Software (\d*).(\d*).(\d*)", 1)
  If Number($aVersion[0]) > $iFirst Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) > $iMid And Number($aVersion[2]) > $iLast) Then
    $iFirst = Number($aVersion[0])
    $iMid = Number($aVersion[1])
    $iLast = Number($aVersion[2])
    $iHighest = $i
  EndIf
Next

MsgBox(0, $iHighest, $aFolders[$iHighest])
Run($aFolders[$iHighest] & "\app\windows\program.exe")

Credits to @Nine

I think for 3 levels its not that easy.

I just created a test setup with empty folders and it says that 10.2.4 is the highest version, although 10.3.3. is higher.

image.png.6c22bf86821e4c90266c457db2131ca3.png

Link to comment
Share on other sites

What about this? Works for me.

#include <File.au3>

Const $sRoot = "C:\Apps\Temp"

Local $aFolders = _FileListToArrayRec($sRoot, "Software*", $FLTAR_FOLDERS, Default, Default, $FLTAR_FULLPATH)

_ArrayDisplay($aFolders)

Local $aVersion, $iFirst, $iMid, $iLast, $iHighest

For $i = 1 to $aFolders[0]
  $aVersion = StringRegExp($aFolders[$i], "Software (\d*).(\d*).(\d*)", 1)
  If Number($aVersion[0]) > $iFirst Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) > $iMid) Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) = $iMid And Number($aVersion[2]) > $iLast) Then
    $iFirst = Number($aVersion[0])
    $iMid = Number($aVersion[1])
    $iLast = Number($aVersion[2])
    $iHighest = $i
  EndIf
Next

MsgBox(0, $iHighest, $aFolders[$iHighest])
Run($aFolders[$iHighest] & "\app\windows\program.exe")

Credits to @Nine again. ☺️

Edited by Luke94
Link to comment
Share on other sites

Thanks @Luke94 now it finds the file and executes it correctly. :) 

Only one additional thing.

To run the program.exe correctly it requires the path of the program.exe file as "workingdir" when using the Run function.

Is there an easy way to edit the found path and automatically remove the last "TEC.exe" part of the path.

image.png.dc4eafc0da1a289ec8aeb73762a03220.png

Because to run the .exe I need to execute the "Run" command with "C:\REC\TEC7\app\tec\windows\" as working directory otherwise the application gives me an error during startup.

It only works when Run is executed like this:

Local $path = "C:\TEC\TEC7\app\tec\windows\"
Run($path & "TEC.exe", $path, @SW_MAXIMIZE )

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Is it possible to ignore the sign between  "TEC" and the version number? I tested the script on a other PC where one version was installed in a folder using "_" instead of space between TEC and the version. 

image.png.d3f5cac917533aaa01a92e41148012cf.png

The best would be if it only checks for the version number and ignores TEC at all.

But when I use it like this:

$aVersion = StringRegExp($aFolders[$i], "(\d*).(\d*).(\d*)", 1)

instead of this (working fine as long as format is "TEC version" and not "TEC_version" or a mix) :

$aVersion = StringRegExp($aFolders[$i], "TEC (\d*).(\d*).(\d*)", 1)

It only returns "4" from row 0 as it does not find a version at all and the rest of the rows stay empty.

Can someone help me with the syntax on that?

Thanks for your help :)

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...