Vue调用本地EXE程序
设计思路
创建一个简洁的界面,展示如何调用EXE程序
实现通过自定义URL协议(SEngineVue://)启动EXE的功能
添加错误处理和状态反馈
使用现代UI设计,确保良好的用户体验
这是一个用于注册 SEngineVue:// 协议处理程序的注册表文件
当系统遇到 SEngineVue:// 开头的链接时,会自动启动指定的可执行文件
路径指向:D:\Program Files\arrmclient\SEngine\bin\SEngine.exe
使用方法:
将上述内容保存为 .reg 文件(如 SEngineVue.reg)
双击运行该文件将其导入注册表
确认导入提示即可完成协议注册
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\SEngineVue]
@="URL:SEngineVue Protocol Handler"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\SEngineVue\shell]
[HKEY_CLASSES_ROOT\SEngineVue\shell\open]
[HKEY_CLASSES_ROOT\SEngineVue\shell\open\command]
@="D:\\Program Files\\arrmclient\\SEngine\\bin\\SEngine.exe"
<template><header class="firstTitle"><!-- <img :src="titleImg" alt="" /> --><span v-if="props.title === '安全防控'" @click="handleSecurityClick" style="cursor: pointer">{{ props.title }}</span><span v-else>{{ props.title }}</span></header><slot></slot>
</template><script setup>
const props = defineProps({titleImg: {type: String,default: "",},title: {type: String,default: "",},
});// 打开本地.exe文件,Windows 注册表脚本位置(./SEngineVue.reg)
// 前提:在目标电脑中执行注册表脚本
const handleSecurityClick = () => {window.location.href = "SEngineVue://";
};
</script><style lang="scss">
.firstTitle {width: 100%;height: 44px;margin-bottom: 8px;background-image: url("@/assets/publicImg/bg_large_title.png");background-position: 100% 100%;background-size: 100% 100%;background-repeat: no-repeat;display: flex;align-items: center;font-family: YouSheBiaoTiHei;font-size: 32px;span {background: linear-gradient(to top, #f9f8f8 20%, #7dc2ff 90%);-webkit-background-clip: text; /* 使背景颜色应用于文字 */-webkit-text-fill-color: transparent; /* 填充颜色变为透明 */margin-left: 42px;}img {margin-left: 42px;height: 36px;width: auto;}
}
</style>
主启动功能:点击"启动SEngine.exe"按钮,通过SEngineVue协议调用本地EXE程序
带参数启动:演示如何传递参数给EXE程序
错误模拟:展示当协议未注册或程序不存在时的错误处理
状态反馈:提供操作成功或失败的可视化反馈
使用说明
确保已在Windows注册表中按照您提供的.reg文件内容注册了SEngineVue协议
确保SEngine.exe存在于指定的路径中
在浏览器中打开此HTML文件,点击按钮测试功能