Jump to content

A question about Run function


marsL
 Share

Recommended Posts

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!

Link to comment
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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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")
Link to comment
Share on other sites

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