Jump to content

Recommended Posts

Posted

I want to find an executable file and then run that file. The following code produces an error "Unable to execute the external program. Any ideas?

; Shows the filenames of all files in the current directory
$search = FileFindFirstFile(@DesktopDir & "\TD file downloads\*.exe")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    Run($file,@DesktopDir & "\TD file downloads\")
    If @error Then ExitLoop
    
    MsgBox(4096, "File:", $file)
WEnd

; Close the search handle
FileClose($search)
Posted

I want to find an executable file and then run that file. The following code produces an error "Unable to execute the external program. Any ideas?

; Shows the filenames of all files in the current directory
$search = FileFindFirstFile(@DesktopDir & "\TD file downloads\*.exe")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    Run($file,@DesktopDir & "\TD file downloads\")
    If @error Then ExitLoop
    
    MsgBox(4096, "File:", $file)
WEnd

; Close the search handle
FileClose($search)
If there is only one *.exe, it'll never be run, because FileFindFirstFile(0 already found it and FileFindNextFile() is looking for the second "find".
Posted

Your error is due to calling Run() on a folder name:

Run($file,@DesktopDir & "\TD file downloads\")

This needs to point to the found exe.

Also, just use:

#include <File.au3>

$fileList = _FileListToArray ( @DesktopDir & "\TD file downloads\", "*.exe", 1)

If $fileList[0] Then

;Run first found instance

Run(@DesktopDir & "\TD file downloads\" & $fileList[1])

EndIf

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
×
×
  • Create New...