首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AutoIt:运行用FileOpenDialog选择的程序?

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

Stack Overflow用户
提问于 2014-01-14 02:20:54
回答 2查看 2.3K关注 0票数 0

我需要做一个脚本,允许用户运行的软件与某些参数(这应该是键入)。因此,第一步,选择exe。其次,文本输入框应允许用户输入参数。我做不到第一步。

我尝试了这里的第二个示例:FileOpenDialog

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

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2014-01-14 04:52:10

代码语言:javascript
复制
#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
EN

Stack Overflow用户

发布于 2014-01-14 14:01:03

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

代码语言:javascript
复制
#include <FileConstants.au3>
#include <Constants.au3>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21098522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档