AutoIt:运行用FileOpenDialog选择的程序?

时间:2014-01-13 18:20:54

标签: scripting autoit

我需要创建一个脚本,允许用户运行具有某些参数的软件(应该输入)。所以,第一步,选择exe。其次,文本输入框应允许用户输入参数。我无法完成第一步。

我尝试了第二个例子:FileOpenDialog

唯一的修改是我添加的Run命令。当我运行脚本时,我看到可执行文件的完整文件路径但没有运行。我也没有看到错误:

include <FileConstants.au3>
include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the message to display in FileOpenDialog.
    Local Const $sMessage = "Select a single file of any type."

    ; Display an open dialog to select a file.
    Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST)
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")

        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)

        ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog.
        $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)

        ; Display the selected file.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & @CRLF & $sFileOpenDialog)
    Run($sFileOpenDialog)
    EndIf
EndFunc   ;==>Example

2 个答案:

答案 0 :(得分:1)

#include <FileConstants.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the message to display in FileOpenDialog.
    Local Const $sMessage = "Select a single file of any type."

    ; Display an open dialog to select a file.
    Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST)
    If @error Then
        ; Display the error message.
        MsgBox(1, "", "No file was selected.")

        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)

        ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog.
        $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)

        ; Display the selected file.
        MsgBox(1, "", "You chose the following file:" & @CRLF & $sFileOpenDialog)
    Run($sFileOpenDialog)
    EndIf
EndFunc   ;==>Example

这对我有用。 我不知道这个“包括MsgBoxConstants.au3”,我觉得这是不必要的。

Lg Teifun2

答案 1 :(得分:1)

您需要在include之前添加#。第二个包含必须是Constants.au3。当我进行这些更改时,我可以使用您的代码成功启动任何应用程序。

#include <FileConstants.au3>
#include <Constants.au3>