ShellExecute
使用 ShellExecute API 运行外部程序.
ShellExecute ( "filename" [, "parameters" [, "workingdir" [, "verb" [, showflag]]]] )
参数
filename
|
运行文件的名称(类型为 .exe, .txt, .lnk, 等等).
|
parameters
|
[可选] 程序运行时需要的参数. 空白("")为没有参数.
|
workingdir
|
[可选] 工作目录. 空白 ("") 使用当前工作目录.
|
verb
|
[可选] 使用 "verb" ,常见 verb 包含:
$SHEX_OPEN ("open") = 打开指定文件. 文件可以是可执行文件, 文档或文件夹
$SHEX_EDIT ("edit") = 启动编辑器, 并打开指定的文档. 如果 "文件名" 不是文档文件, 函数将失败
$SHEX_PRINT ("print") = 打印指定的文档文件. 如果 "文件名" 不是文档文件, 函数将失败
$SHEX_PROPERTIES ("properties") = 显示文件或者文件夹的属性
更多信息见备注, 默认没有指定的 "verb".
常量定义在 "AutoItConstants.au3"
|
showflag
|
[可选] 程序执行时的显示状态:
@SW_HIDE = 隐藏窗口
@SW_MINIMIZE = 最小化窗口
@SW_MAXIMIZE = 最大化窗口
|
返回值
成功:
|
返回进程 PID. 或 -1, 没有 PID.
|
失败:
|
返回 0, @error 设置为非 0 值.
|
备注
程序运行后脚本将继续执行后面的语句. 要暂停脚本的执行, 直到程序完成, 使用 ShellExecuteWait() 函数代替.
如果没有指定 verb, 则使用默认 verb 方式. 默认 verb 是注册表配置的 verb.
如果注册表没有 verb 默认设置, 则 verb 使用 "open" 值.
如果"open" 也不存在, 则使用注册表列出的第一个 verb 值.
函数示例
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Retrieve the following text file. This can be found in the include folder which is in the installation path of AutoIt.
Local $sWow64 = ""
If @AutoItX64 Then $sWow64 = "\Wow6432Node"
Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\include\_ReadMe_.txt"
; Execute the readme file (.txt) with the default editor used for text files in Windows.
Local $iPID = ShellExecute($sFile)
MsgBox($MB_SYSTEMMODAL, "", "PID: " & $iPID)
EndFunc ;==>Example
----------------------------------------
该函数可以通过命令调用 exect
参见:
ShellExecuteWait, Run, RunWait, RunAs, RunAsWait
exect=ShellExecute('notepad.exe') ;; 启动记事本
exect=ShellExecute('http://tc-image.3dn.ru/forum/5-498-1') ;; 在浏览器中打开链接
exect=ShellExecute('C:\Test\Name.txt','''','''','edit') ;; 在默认编辑器中打开.txt文件
© Аверин Андрей для Total Commander Image Averin-And@yandex.ru
|