RunApp 运行
🎯功能
启动一个程序或者打开一个文件
📜语法
RunApp 文件路径
📥参数
参数 | 数据类型 | 解释 |
---|---|---|
文件路径 | 文本型 | 要运行的程序或文件的路径 |
📤返回
无
💡示例
//启动Windows记事本程序
RunApp "notepad.exe"
//打开网页
RunApp "https://zimaoxy.com"
//高级例子1
//介绍: 部分应 用程序无法使用RunApp命令打开, 故这里提供一个API启动程序命令
//程序路径: 要启动程序的完整路径
//下面两行是API的声明, 请放在脚本开头
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal Hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub zmRunApp(程序路径)
Dim p, DirPath, FileName
p = InStrRev(程序路径, "\")
DirPath = Left(程序路径, p)
FileName = Right(程序路径, Len(程序路径) - p)
ShellExecute GetDesktopWindow, "open", FileName, vbNullString, DirPath, 5
End Sub
//调用例子如下:
zmRunApp "C:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe"
//高级例子2
//介绍: 如果你要执行CMD命令行内容, 可以尝试使用本函数
//命令行: 命令行代码内容, 如果存在文件路径, 请给路径加单引号, 例如 "'C:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe'"
Function zmRunCMD(命令行)
Dim fs, tempFile, f, tempText
命令行 = Replace(命令行, "'", chr(34))
Set fs = CreateObject("scripting.FileSystemObject")
tempFile = fs.GetSpecialFolder(2) & "\" & fs.GetTempName
RunApp "cmd.exe /c " & 命令行 &" > " & tempFile
//如果命令行执行耗时较久, 请加长延时的时间
Delay 1000
If fs.FileExists(tempFile) Then
Set f = fs.openTextFile(tempFile, 1)
tempText = f.ReadAll
f.Close
Set f = Nothing
End If
Set fs = Nothing
zmRunCMD = tempText
End Function
//调用例子, 下面是执行dir命令行并输出结果
TracePrint zmRunCMD("dir")
//高级例子3
//一些系统自带参数的启动程序, 更多请程序参数请自行搜索
// 用画图程序打开图片
RunApp "mspaint.exe C:\紫猫帅照.jpg"
//以下代码例子是从网上搜索得到的
//打开任务管理器
RunApp "TASKMGR.EXE"
//打开我的文档
RunApp "explorer.exe"
//打开通讯簿
RunApp "wab.exe"
//打开事件查看器
RunApp "eventvwr.msc"
//打开数据源 (ODBC).
RunApp "odbcad32.exe"
//打开性能
RunApp "perfmon.msc"
//打开服务
RunApp "services.msc"
//打开本地安全策略
RunApp "secpol.msc"
//打开计算机管理
RunApp "compmgmt.msc"
//打开画图
RunApp "mspaint.exe"
//打开录音机
RunApp "sndrec32.exe"
//打开计算器
RunApp "calc.exe"
//打开红心大战
RunApp "mshearts.exe"
//打开空当接龙
RunApp "freecell.exe"
//打开扫雷
RunApp "winmine.exe"
//打开蜘蛛纸牌
RunApp "spider.exe"
//打开纸牌
RunApp "sol.exe"
//打开记事本
RunApp "notepad.exe"
//打开命令提示符
RunApp "cmd.exe"
//打开写字板
RunApp "wordpad.exe"
//打开"我的电脑"----/n可以换成/e 将会以资源管理器的方式打
RunApp "explorer.exe /n,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
//打开"我的文档"
RunApp "explorer.exe /n,::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
//打开"网络邻居"
RunApp "explorer.exe /n,::{208D2C60-3AEA-1069-A2D7-08002B30309D}"
//打开"回收站"
RunApp "explorer.exe /n,::{645FF040-5081-101B-9F08-00AA002F954E}"
//打开"控制面板"
RunApp "rundll32.exe shell32.dll,Control_RunDLL"
//打开"系统属性-常规"
RunApp "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,0"
//打开"系统属性-计算机名"
RunApp "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,1"
//打开"系统属性-硬件"
RunApp "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,2"
//打开"系统属性-高级"
RunApp "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,3"
//打开"系统属性-系统还原"
RunApp "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,4"
//打开"系统属性-自动更新"
RunApp "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,5"
//打开"系统属性-远程"
RunApp "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,6"
//打开"辅助选项 属性-键盘"
RunApp "rundll32.exe shell32.dll,Control_RunDLL access.cpl,,1"
//打开"辅助选项 属性-声音"
RunApp "rundll32.exe shell32.dll,Control_RunDLL access.cpl,,2"
//打开"辅助选项 属性-显示"
RunApp "rundll32.exe shell32.dll,Control_RunDLL access.cpl,,3"
//打开"辅助选项 属性-鼠标"
RunApp "rundll32.exe shell32.dll,Control_RunDLL access.cpl,,4"
//打开"辅助选项 属性-常规"
RunApp "rundll32.exe shell32.dll,Control_RunDLL access.cpl,,5"
//打开"添加/删除程序 属性-程序"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Appwiz.cpl,,0"
//打开"添加/删除程序 属性-安装/卸载"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Appwiz.cpl,,1"
//打开"添加/删除程序 属性-Windows安装程序"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Appwiz.cpl,,2"
//打开"添加/删除程序 属性-启动盘"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Appwiz.cpl,,3"
//打开"显示 属性-主题"
RunApp "rundll32.exe shell32.dll,Control_RunDLL desk.cpl"
//打开"显示 属性-背景"
RunApp "rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0"
//打开"显示 属性-屏幕保护程序"
RunApp "rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,1"
//打开"显示 属性-外观"
RunApp "rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,2"
//打开"显示 属性-设置"
RunApp "rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3"
//打开"Internet 属性-常规"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,0"
//打开"Internet 属性-安全"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,1"
//打开"Internet 属性-隐私"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,2"
//打开"Internet 属性-内容"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,3"
//打开"Internet 属性-连接"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,4"
//打开"Internet 属性-程序"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,5"
//打开"Internet 属性-高级"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,6"
//打开"区域设置 属性-区域设置"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,0"
//打开"区域设置 属性-语言"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,1"
//打开"区域设置 属性-高级"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,2"
//打开"游戏控制器-一般"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Joy.cpl,,0"
//打开"鼠标 属性"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Main.cpl"
//打开"鼠标 属性-指针"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Main.cpl,,1"
//打开"鼠标 属性-指针选项"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Main.cpl,,2"
//打开"鼠标 属性-轮"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Main.cpl,,3"
//打开"鼠标 属性-硬件"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Main.cpl,,4"
//打开"多媒体 属性-音量"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,0"
//打开"多媒体 属性-声音"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,1"
//打开"多媒体 属性-音频"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,2"
//打开"多媒体 属性-语声"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,3"
//打开"多媒体 属性-硬件"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,4"
//打开"调制解调器 属性"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Modem.cpl"
//打开"日期/时间 属性-日期和时间"
RunApp "rundll32.exe shell32.dll,Control_RunDLL timedate.cpl"
//打开"日期/时间 属性-时区"
RunApp "rundll32.exe shell32.dll,Control_RunDLL timedate.cpl,,1"
//打开"电源选项 属性-电源使用方案"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Powercfg.cpl"
//打开"拨号属性"
RunApp "rundll32.exe shell32.dll,Control_RunDLL Telephon.cpl"
//打开"ODBC数据源管理器 属性-用户DSN"
RunApp "rundll32.exe shell32.dll,Control_RunDLL odbccp32.cpl"
//打开"添加打印机向导"
RunApp "rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter"
//打开"复制磁盘"
RunApp "rundll32.exe diskcopy.dll,DiskCopyRunDll"
//打开Windows的“字体”档案夹
RunApp "rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL FontsFolder"
// 执行“添加新调制解调器”向导
RunApp "rundll32.exe shell32.dll,Control_RunDLL modem.cpl,,add"
📘备注
- 如果遇到
RunApp
启动失败的话, 请参考上面代码例子里的解决方法