需求:在安装应用时需要安装virbox等应用程序对electron应用进行许可验证
解决方案:
(1)添加nsis脚本路径
builderOptions: {
nsis: {
oneClick: false, // 是否一键安装
perMachine: false, //辅助安装,(选择按机器还是按用户)。true时代表始终按用户安装。
allowElevation: true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
allowToChangeInstallationDirectory: true, // 允许修改安装目录
include: 'installer.nsh', //NSIS脚本
},
}
(2)在项目根路径下新建build文件夹,并新建installer.nsh文件
(3)编写installer.nsh(请求管理员权限,清空某个文件夹,携带参数静默安装程序)
!macro customHeader
RequestExecutionLevel admin
!macroend
!macro customInstall
RMDir /r "C:\ProgramData\SenseShield\ss"
ExecWait '"$INSTDIR\resources\XXX.exe" /S(安装携带的参数,空格隔开)'
!macroend
(4)配置extraResources将exe复制到electron安装目录的resources文件夹下,以便程序索引
extraResources: [
// 程序
{
from: 'build/xxx.exe',
to: './'
},
]