Jump to content
CodingMonkey81

SOLVED:Running an installer with a wildcard

Recommended Posts

CodingMonkey81

All,

I'm working on automating the update process for a piece of software that we use at my company. The installer file always contains the version number as a part of the file name (eg InstallFile_9342.msi) and the numbers always change with every update.

How do I use AutoIt to run the program? I know I can't use a wildcard in place of the numbers when using the "Run" command. 

I tried 

Local $aArray = _FileListToArray("C:\path\to\file", "InstallFile_*.msi", 0, 1)
Run("$aArray")

and I also tried

Local $bInstall = FileFindFirstFile("InstallFile_*.msi")
Run("$bInstall")

and neither worked. 

Can someone please point me in the right direction? I've done some searching on the forum and haven't found anyone in a similar situation before.

Thanks!

Edited by CodingMonkey81

Share this post


Link to post
Share on other sites
czardas

If the numbers are always 4 digits (or an equal number of digits), then you could just filter part of the file name (using _FileListToArray) and then use _ArraySort(). The last array element ought to be the latest version. You could try this approach to see if it works in your situation, and find out if there are any extra steps needed.

Edited by czardas
  • Like 1

Share this post


Link to post
Share on other sites
CodingMonkey81

Do you know of any "real world" examples of how to use the two functions you've mentioned?

Share this post


Link to post
Share on other sites
Earthshine

this came straight from the help file. plus in the help file you can just open and run it from autoit

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

Example()

Func Example()
    ; List all the files and folders in the desktop directory using the default parameters and return the full path.
    Local $aFileList = _FileListToArray(@DesktopDir, Default, Default, True)
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Exit
    EndIf
    ; Display the results returned by _FileListToArray.
    _ArrayDisplay($aFileList, "$aFileList")
EndFunc   ;==>Example

 

; using a 2D array

#include <Array.au3>

Local $avArray[5][3] = [ _
        [5, 20, 8], _
        [4, 32, 7], _
        [3, 16, 9], _
        [2, 35, 0], _
        [1, 19, 6]]

_ArrayDisplay($avArray, "$avArray BEFORE _ArraySort()")
_ArraySort($avArray, 0, 0, 0, 0)
_ArrayDisplay($avArray, "$avArray AFTER _ArraySort() ascending column 0")
_ArraySort($avArray, 0, 0, 0, 1)
_ArrayDisplay($avArray, "$avArray AFTER _ArraySort() ascending column 1")
_ArraySort($avArray, 0, 0, 0, 2)
_ArrayDisplay($avArray, "$avArray AFTER _ArraySort() ascending column 2")

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
CodingMonkey81

Ok. I'll have to look at this and see what I can figure out. Honestly (for the limited "coding" skills I have), it might just be easier to run the file manually.

Share this post


Link to post
Share on other sites
Earthshine
1 hour ago, CodingMonkey81 said:

Ok. I'll have to look at this and see what I can figure out. Honestly (for the limited "coding" skills I have), it might just be easier to run the file manually.

try this for a example of how to load an array and sort it. just substitute your path and your search argument into the first two arguments passed to _FileListToArray

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

Local $aArray = _FileListToArray("C:\path\to\file", 'InstallFile*.msi', Default, True)
_ArraySort($aArray, 1) ; sorts descending, latest version on top at element 0
;~ _ArrayDisplay ($aArray)

Local $str = "msiexec /i """ & $aArray[0] & """ /quiet /qn"
ConsoleWrite($str)
RunWait($str)

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

I just used any old msi i could get to test, but sorting descending should leave the latest version on top so then you build your installer string and run it. any questions, come on back.

the tripple """ are to encapsulate the path in double quotes, in case you have spaces in the path. The ConsoleWrite writes out what it finds in the array to help you debug in case the command is wrong. mine looked like this for a test. (I'm on fire now folks)

 

Capture.PNG

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
ViciousXUSMC

FileListToArray() works great.

I also use RegEx if I plan to only have one installer at any given time but the numbers change so that it can match any number.

 

If your version numbers end up being set in a way that you cant not always get the correct result with an ascending/descending list, use FileGetTime() and then you can sort by modified/created dates.

  • Like 1

Share this post


Link to post
Share on other sites
Earthshine

excellent point ViciousXUSMC. my best friend is also ex USMC btw


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
CodingMonkey81
On 11/29/2017 at 9:57 AM, Earthshine said:

try this for a example of how to load an array and sort it. just substitute your path and your search argument into the first two arguments passed to _FileListToArray

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

Local $aArray = _FileListToArray("C:\path\to\file", 'InstallFile*.msi', Default, True)
_ArraySort($aArray, 1) ; sorts descending, latest version on top at element 0
;~ _ArrayDisplay ($aArray)

Local $str = "msiexec /i """ & $aArray[0] & """ /quiet /qn"
ConsoleWrite($str)
RunWait($str)

 

Ok. So I tried this (modifying the necessary portions) but all it does it pop up a dialog box with the information (ArrayDisplay) The display does show the correct file in row 0. I don't know how to make the "leap" from getting the information to using it.

 

Also, I removed the "/quiet /qn" flags as I need the GUI to come up.

 

Thanks!

Message Box.edigted.JPG

Edited by CodingMonkey81
Adding Screenshot

Share this post


Link to post
Share on other sites
Earthshine

that's funny.  I see something like this. I think you are feeding it a garbage path. the array display function is only called for your convenience. once closed, it builds the string and executes it. I saw garbage in your results. Don't know what to tell you. comment out the arraydisplay like this. just uncomment it if you care to see the list of msi files it finds. that's all. 

 

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

Local $aArray = _FileListToArray("w:\editdocs\build", '*.msi', Default, True)
_ArraySort($aArray, 1) ; sorts descending, latest version on top at element 0
;~ _ArrayDisplay ($aArray)

;~ Local $str = "msiexec /i """ & $aArray[0] & """ /quiet /qn"
Local $str = "msiexec /i """ & $aArray[0] & """
ConsoleWrite($str)
RunWait($str)

Capture.PNG

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
careca

But still, array[0] should retrieve the count, and not a path, right?

Only now noticed the sort.

" I don't know how to make the "leap" from getting the information to using it. "

What do you mean? that information is

$aArray[0]
Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Earthshine

yeah, he doesn't get that the information he wants is in $aArray[0] (element zero, first element) and that you need to construct the command to install it using msiexec as follows.

Local $str = "msiexec /i """ & $aArray[0] & """
ConsoleWrite($str)
RunWait($str)

 


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
CodingMonkey81
On 12/6/2017 at 4:08 PM, Earthshine said:

yeah, he doesn't get that the information he wants is in $aArray[0] (element zero, first element) and that you need to construct the command to install it using msiexec as follows.

Local $str = "msiexec /i """ & $aArray[0] & """
ConsoleWrite($str)
RunWait($str)

 

If I use 

Local $str = "msiexec /i """ & $aArray[0] & """

Autoit SyntaxProdCheck throws me an error message. I have to add another " at the end for it to not error out during the check.

 

If I use this:

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
Local $aArray = _FileListToArray("D:\Path\To\File", 'StaticFileName*.msi', Default, True)
_ArraySort($aArray, 1) ; sorts descending, latest version on top at element 0
;_ArrayDisplay ($aArray)

;Local $str = "msiexec /i """ & $aArray[0] & """
ConsoleWrite($str)
RunWait($str)

The SyntaxProdCheck gives me a warning: "warning: $str: possibly used before declaration."

 

I'm still not sure where I'm going wrong as I'm trying (and failing) to understand where my issue is.

Thank you for the help in this. I do want to learn this even if it's a bit over my head.

Share this post


Link to post
Share on other sites
Earthshine
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
Local $aArray = _FileListToArray("D:\Path\To\File", 'StaticFileName*.msi', Default, True)
_ArraySort($aArray, 1) ; sorts descending, latest version on top at element 0
;_ArrayDisplay ($aArray)

Local $str = "msiexec /i """ & $aArray[0] & """"
ConsoleWrite($str)
RunWait($str)

You commented out the declaration of $str in your code, and I fixed the quote thing. try that. Compare the code in your post to this post and see what a difference a stray ';' character can cause.

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
CodingMonkey81
On 12/6/2017 at 2:25 PM, Earthshine said:

that's funny.  I see something like this. I think you are feeding it a garbage path. the array display function is only called for your convenience. once closed, it builds the string and executes it. I saw garbage in your results. Don't know what to tell you. comment out the arraydisplay like this. just uncomment it if you care to see the list of msi files it finds. that's all. 

 

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

Local $aArray = _FileListToArray("w:\editdocs\build", '*.msi', Default, True)
_ArraySort($aArray, 1) ; sorts descending, latest version on top at element 0
;~ _ArrayDisplay ($aArray)

;~ Local $str = "msiexec /i """ & $aArray[0] & """ /quiet /qn"
Local $str = "msiexec /i """ & $aArray[0] & """
ConsoleWrite($str)
RunWait($str)

Capture.PNG

Ok. So, If I use this code:

 

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
Local $aArray = _FileListToArray("D:\Path\To\File", 'StaticFileName*.msi', Default, True)
_ArraySort($aArray, 1) ; sorts descending, latest version on top at element 0
_ArrayDisplay ($aArray)

;Local $str = "msiexec /i """ & $aArray[0] & """
;ConsoleWrite($str)

 

I get a dialog box that does show the correct path.

Share this post


Link to post
Share on other sites
CodingMonkey81
24 minutes ago, Earthshine said:
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
Local $aArray = _FileListToArray("D:\Path\To\File", 'StaticFileName*.msi', Default, True)
_ArraySort($aArray, 1) ; sorts descending, latest version on top at element 0
;_ArrayDisplay ($aArray)

Local $str = "msiexec /i """ & $aArray[0] & """"
ConsoleWrite($str)
RunWait($str)

You commented out the declaration of $str in your code, and I fixed the quote thing. try that. Compare the code in your post to this post and see what a difference a stray ';' character can cause.

 

Holy crap, it works!

If I understand this correctly (in the above code) the commented out item is the dialog box and it's being commented out because we don't see to see it but it's there for checking purposes. Right?

I somewhat understand the rest. It's taking the file(s) that it finds, sorting them with the newest on "top", write it to the $aArray function, creates  a "run" command for the msi file using the $aArray value and then runs it. 

To me this feel like learning a foreign language; when it's written out I can understand it but trying to write something from scratch that's correct is much more difficult.

 

Thank you all again!

Edited by CodingMonkey81
Grammer

Share this post


Link to post
Share on other sites
Earthshine

yes, we comment out the ArrayDisplay call. that is for testing purposes to see if we have the correct results before we fire the real function that does the work. the line 

Local $str = "msiexec /i """ & $aArray[0] & """"

declares the string variable $str and also sets it to the command that installs your desired program

let this be your first tool you have created. go forth and prosper in code. come back and start new threads for other problems! NEVER stop learning and growing yourself!

 

you CAN code! you use pseudo code methods.

describe what you want to do in bullet points even, organize according to functionality you want to provide and create more bullets underneath to flesh out your algorithm. the computer language nonsense is just syntax. once you learn AutoIt you could probably learn another language easier. my first was BASIC and Assembler for the 6809e Motorola processor (64K Color Computer, LOL)

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
careca

You had this:

;Local $str = "msiexec /i """ & $aArray[0] & """ <---- It was commented out, so not read.
ConsoleWrite($str) ;<----here you used the variable $str, but since it was not set, you got the error, it's like, it was the first time the script has "seen" that variable.
RunWait($str)

 

Edited by careca
  • Like 1

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Earthshine

he solved it mate


My resources are limited. You must ask the right questions

 

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

  • Similar Content

    • RHolmes
      By RHolmes
      I have a program that has a control that changes color a few seconds into running. So ideally, I would poll this to tell when an event has occurred. 
      I can't seem to retrieve the correct color value for a control. It always seems to return white indicating that its selecting somewhere else in the window.
      In the PixelGetColor call I'm adding half the width to the x value and subtracting half the height to the y value  in order to get the center of the control. (assuming the coords returned by ControlGetPos are top left - which i can't be sure of) But I've also tried without modifying the x/y and with changing the PixelCoordMode option to 2. Maybe I'm making a silly mistake and can't see it? Any help would be appreciated.
      Code is below:
      Opt("PixelCoordMode", 0)
      FileChangeDir( "C:\Where\My\File\Is" );
      Run( "MyProgram.exe" )
      Local $hClient = WinWaitActive( $CLIENT_TITLE, "", 10 )
      Local $systemIndicatorClassNN= "[CLASS:Qt5QWindowIcon; INSTANCE:99]"
      Local $hSystemIndicator = ControlGetHandle ( $hClient, "", $systemIndicatorClassNN)
      Local $xywh = ControlGetPos ( $hClient, "", $hSystemIndicator )
      For $i = 10 To 1 Step -1
            $color = PixelGetColor ( $xywh[0] + ($xywh[2]/2), $xywh[1] - ($xywh[3]/2), $hClient )
            LogToFile( $color )
            Sleep( 2000 )
      Next
    • VAN0
      By VAN0
      Hello.
      I have a program XX that asks for user confirmation on exit, which hangs the system reboot/shutdown process until I confirm. So I decided create a autoit script that would automatically close that dialog and let the system reboot/shutdown.
      The problem I'm facing is that my scripts now exits before the XX.
      Is there a way delay script exit until the XX is closed but only when system is rebooting/shutting down?
       
      Thank you.
    • Simpel
      By Simpel
      Hi, I created a gui with date field but formatted as time in HH:mm. It always shows "now-time". Even if I try to set it with GUICtrlSetData.
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm" ; Just display hours and minutes <<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUICtrlSetData($idDate, "00:00") ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example How can I set the time field with another time and how can this field be set blank?
      Regards, Conrad
    • hunte922
      By hunte922
      Edit: The solution! Maybe?
       
      I need to download an image from a website using AutoIt but the download, when viewed in a text editor, does not appear to be the same as if I had downloaded it from a web browser.
      Could anyone help me figure out why this is happening?
      I've already tried _INetGetSource, InetGet, _IENavigate, wget, this, and a few .bat and .vbs scripts.
       
      Example Code:
      #include <Inet.au3> Local $source = _INetGetSource("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a") Local $newfile = FileOpen(@ScriptDir & "\test.txt", 2) FileWrite($newfile, $source) FileClose($newfile) Image URL: http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a
      Screenshot attached.

    • TommyDDR
      By TommyDDR
      Hi,
      I have to set a resizing mode to differents controls in a hidden gui, that gui is initialised (hidden) and resized by a WinMove.
      But when i show it, control are not resized where thez should.
      There is a simple code that reproduce the problem.
      Same gui, same content, one displayed then moved, the other moved then displayed :
      #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $gui[2] Global $labels[2] Global $taille[2] = [200, 100] For $i = 0 To UBound($gui, 1) - 1 $gui[$i] = GUICreate($i, $taille[0], $taille[1], $i * ($taille[0]+100) + 500, (@DesktopHeight-$taille[1])/2) GUISetOnEvent($GUI_EVENT_CLOSE, "quit", $gui) $labels[$i] = GUICtrlCreateLabel("Test resizing...", $taille[0]-105, $taille[1]-25, 100, 20) GUICtrlSetBkColor($labels[$i], 0xE0E0E0) GUICtrlSetResizing($labels[$i], BitOR($GUI_DOCKRIGHT, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH, $GUI_DOCKHEIGHT)) Next GUISetState(@SW_SHOW, $gui[0]) For $i = 0 To UBound($gui, 1) - 1 WinMove($gui[$i], "", Default, Default, $taille[0]+100, $taille[1]+100) Next GUISetState(@SW_SHOW, $gui[1]) While(True) Sleep(10) WEnd Func quit() Exit EndFunc Is that a bug or do miss i something ?
      EDIT : This bug disapear if gui is shown at lease one time (even if hide then)
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.