autoit 编译脚本与命令行参数

本文详细介绍了AutoIt脚本如何处理命令行参数,并通过特殊数组$CmdLine来获取这些参数。同时,文章还讲解了如何使用Aut2Exe工具将AutoIt脚本编译成可执行文件,包括通过图形界面、右键菜单和命令行方式进行编译的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、命令行参数:

当我们传递命令行参数到AutoIt脚本中的时候,AutoIt会初始化一个特殊的数组 $CmdLine.   注意, 脚本文件名不算进参数; 请使用 @ScriptName 代替脚本名称.  一个参数中如果含有空格,必须使用"双引号"把内容围住.  已编译的 脚本同样也能接受命令行参数. 请看下面代码:

$CmdLine[0] ;参数的数量
$CmdLine[1] ;第一个参数 (脚本名称后面)
$CmdLine[2] ;第二个参数等等
...
$CmdLine[$CmdLine[0]] ;可以用来表示得到最后一个参数...

 

如果您的脚本是像下面这样被运行的话:

    AutoIt3.exe myscript.au3 参数1 "这是 一个其它参数"

$CmdLine[0] 等价于... 2

$CmdLine[1] 等价于... 参数1

$CmdLine[2] 等价于... 这是一个其它参数

@ScriptName 等价于... myscript.au3

除开 $CmdLine 之外还有一个变量叫做 $CmdLineRaw ,它保存着完整的未被拆分的命令行语句, 对于上面这个例子:

$CmdLineRaw 等价于... myscript.au3 参数1 "这是一个其它参数"

 

如果脚本已经被编译,那么得到的值将会是下面这个样子:

    myscript.exe 参数1 "这是 一个其它参数"

$CmdLineRaw 等价于... 参数1 "这是一个其它参数"


2、编译脚本

Aut2Exe 可以有三种使用方法:

方法 1 - 开始菜单

只在完整安装有效(汉化版本因为有强大的ACNWrapper/AutoIt3Wrapper所以去掉快捷方式,这里只是给使用英文原版的做个介绍).

1.  点击开始菜单并浏览 AutoIt v3 组.

2.  点击 Script Compiler \ Convert .au3 to .exe

3.  Aut2Exe 主界面就应该出现.

       

4.  使用 Browse(英文版)/浏览(B)(汉化版) 按钮选择您的输入 (.au3) 和输出 (.exe) 文件.

5.  If you like you can change the icon of the resulting .exe - just browse to the icon you want (some example icons are supplied inProgram Files\AutoIt3\Aut2Exe\Icons).

6.  The only other option you might wish to change is the compression level (especially if using FileInstall to add extra files).  Use theCompression menu to set this.  As with all compression routines the better the compression you select the slower it will be.  However, no matter what compression level you select the decompression speed (when the .exe is run) is the same.

7.  Click on Convert to compile the script.

Note: scripts can be compile with .a3x extension. They should be run with AutoIt.exe filename.a3x. The .a3x contains the script itself with all referred #include plus the FileInstall files. This format allow to distribute smaller files as they don't include the AutoIt3.exe in each compile script. You still need to have it accessible on the target machine but just AutoIt3.exe.

 

方法 2 - 右键点击

只在完整安装有效(汉化版已使用ACNWrapper工具替代).

1.  在资源管理器里面找到您需要编译的脚本文件(.au3).

2.  在脚本文件上面点击右键.

       

3.  The file will be silently compiled with the same filename - just with a .exe extension.

When compiling in this way, Aut2Exe uses current icon/compression settings (from the last time Aut2Exe was run manually as in method 1).

 

方法 3 - 命令行

Aut2Exe.exe 程序可以运行于下列命令行:

    Aut2exe.exe /in <infile.au3> [/out <outfile.exe>] [/icon <iconfile.ico>] [/comp 0-4] [/nopack] [x64] [/bin <binfile.bin>]

Where

开关 用法 默认值
/in<infile.au3> 指定要进行编译的脚本的完整路径.无. 输入文件 必须 指定
/out<outfile.exe> 指定编译后,生成的可执行文件的完整路径.
<outfile.a3x> 指定编译后,生成的已编译文件(*.a3x)的完整路径.
和输入脚本文件名相同,但是扩展名为 .exe
/icon<iconfile.ico> 指定已编译可执行文件要使用的图标的完整路径 .默认 AutoIt 图标
/comp指定编码脚本使用的压缩等级 (这个和 UPX 加壳压缩没关系).
它只能是数字的 0(无) 和 4 (最大).[原文档是and(和)不是to(到)]
2
/nopack指定输出的可执行文件不进行外部的 UPX 压缩.压缩
/pack指定输出的可执行文件进行外部的 UPX 加壳压缩.压缩
/x64指定输出的可执行文件为 x64 系统构架的程序.参考说明
/x86Specifies that the script should be compiled for use on systems with x86 (32-bit) architecture.see notes
/console指定输出的文件为一个控制台程序.Windows 应用程序 (/gui)
/gui指定输出的文件为一个 Windows 应用程序.Windows 应用程序 (/gui)
/bin<binfile.bin> 指定根文件(AU3脚本的执行体)的完整路径 .在 Aut2exe 文件夹中搜索


命令行例子

/in c:\myscript.au3 /out c:\myapp.exe /icon c:\myicon.ico /x64

Will result in the creation of c:\myapp.exe with normal compression which will use the specified icon and be compiled for use on x64 system architecture.

/in c:\myscript.au3

will result in the creation of a unicode c:\myscript.exe with normal compression which will use the default AutoIt icon for use on win_32 systems.

 

 

命令行说明

Long filenames should be enclosed in double-quotes like  "C:\Program Files\Test\test.au3".

With the exception of /in all switches are optional.

By default, the 32-bit compiler produces a 32-bit binary and the 64-bit compiler produces a 64-bit binary. Use the /x86 and /x64 parameters to explicitly specify the output.

The /pass and /nodecompile switches are redundant as of version 3.2.8.1. They will be ignored if used and have been removed from this list.

/ansi 和 /unicode 开关在 3.3.0.0 版本后已经是多余的.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值