Sign in to follow this  
Followers 0
marsL

A question about Run function

5 posts in this topic

Hello everyone, I've a question - how I can run any .exe file with function "*.exe" ?

I'm trying to create script with who to run latest version of Winamp without rename every time .exe file

Example:

from "winamp56_pro_all.exe" to "winamp5601_pro_all.exe"

I tried script:

Run ("Pro\*.exe")

but it's not work.

The function:

FileDelete("Pro\*.exe")

work, but

Run ("Pro\*.exe")

is not :S

any ideas? Thanks in advance!

Share this post


Link to post
Share on other sites



Assuming that all the WinAmp EXEs are in the same directory & that the latest one has the latest file creation time, you can:

Create an array of all the EXEs and then loop through that array with FileGetTime and get the latest EXE and return and run that one

Do the same thing with FileFindFirstFile and FileFindNextFile...find the newest file and return and run it

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can't use run this way. Filedelete supports wildcards whereas run doesn't.

You could use _FileListToArray to get a list of all exe files in a directory and then decide which exe to run.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks, but I wrote following script and it works fine

If FileExists ("Pro\*.exe") Then
    FileCopy ("Pro\*.exe","Pro\Winamp.exe")
    Run("Pro\Winamp.exe /S")

    ProcessWait("bundle2.exe")
    ProcessClose("bundle2.exe")

    ProcessWait("EmusicClient.exe")
    ProcessClose("EmusicClient.exe")
    
    ProcessWaitClose("Winamp.exe")
    FileDelete("Pro\*.exe")
EndIf

; eMusic Uninstall
ProcessClose ("EMusicClient.exe")
Run (@ProgramFilesDir & "\Winamp\eMusic\Uninst-eMusic-promotion.exe /S")

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

In your 2nd example code, you're running Winamp.exe without any placeholder. But frankly, working with placeholders when it comes to such critical stuff as renaming files is a bad idea. Just too much stuff that can go wrong. If that exe's particular name changes between patches and you don't want to update your script every time to accommodate for that, you could look into using regular expressions. Perhaps something like this:

#include <File.au3>
Dim $szDrive, $szDir, $szFName, $szExt
$aExeList = _FileListToArray(@ScriptDir, "*.exe")
If IsArray($aExeList) Then
    For $i = 1 To $aExeList[0]
        If StringRegExp($aExeList[$i], "(?i)winamp(\d{1,2})_pro_all.exe") Then
            $aPath = _PathSplit(@ScriptDir & "\" & $aExeList[$i], $szDrive, $szDir, $szFName, $szExt)
            Run($aExeList[$i], $aPath[1] & $aPath[2])
            ExitLoop
        EndIf
    Next
EndIf

(\d{1,2})
tells the StringRegExp() function to look for one or two digits between "winamp" and "_pro_all.exe". You could set it to
(\d{1,10})
if you were looking for up to 10 digits.

The script runs the first executable that matches the search pattern of the regular expression.

If you have several .exe files with increasing file version numbers in their names (e.g. winamp5601_pro_all.exe, winamp5602_pro_all.exe, winamp57_pro_all.exe and winamp5812_pro_all.exe) then we'd also need the script to not only match the search pattern, but to also compare multiple matches among each other, which can be done fairly easily, too:

#include <File.au3>
#include <Array.au3>
Dim $szDrive, $szDir, $szFName, $szExt
$aExeList = _FileListToArray(@ScriptDir, "*.exe")
If IsArray($aExeList) Then
    Local $aMatches[1] = [0]
    For $i = 1 To $aExeList[0]
        $aResult = StringRegExp($aExeList[$i], "(?i)winamp(\d{1,2})_pro_all.exe", 2)
        If IsArray($aResult) Then
            _ArrayAdd($aMatches, $aResult[1])
        EndIf
    Next
    _ArraySort($aMatches, 1, 1)
    $sExe = "winamp" & $aMatches[1] & "_pro_all.exe"
    $aPath = _PathSplit(@ScriptDir & "\" & $sExe, $szDrive, $szDir, $szFName, $szExt)
    Run($sExe, $aPath[1] & $aPath[2])
EndIf
Edited by Sven

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
Sign in to follow this  
Followers 0