Electron-builder Windows平台打包安装后执行指定的bat脚本(exe)
程序员文章站
2022-03-03 22:39:56
...
1. package.json 文件 build 下的 nsis 和 win 配置
"nsis": {
"oneClick": false,
"allowElevation": true,
"allowToChangeInstallationDirectory": true,
"installerIcon": "./build/icons/icon.ico",
"uninstallerIcon": "./build/icons/icon.ico",
"installerHeaderIcon": "./build/icons/icon.ico",
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"shortcutName": "e-mbms-client",
"include": "./build/script/installer.nsh"
}
"win": {
"icon": "build/icons/icon.ico",
"requestedExecutionLevel": "highestAvailable",
"artifactName": "${productName}_windows_${version}.${ext}",
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
]
}
2. include 核心属性 ,用于exe执行文件安装后执行的nsh脚本(下面是installer.nsh 脚本内容)
!macro customInstall
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" "AppInit_DLLs" "$INSTDIR\ExampleDll64.dll"
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" "LoadAppInit_DLLs" "1"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "xxxx" '"$INSTDIR\resources\windows\exe\xxxx.exe" /start'
ExecWait "$INSTDIR\installed.bat"
!macroend
!macro customUninstall
DeleteRegKey HKCR "*\shell\xxxx"
!macroend
3. ExecWait 执行bat脚本(下面是installed.bat脚本内容)
@ echo off
set currPath=%~dp0
echo e-mbms-client start installation ...
echo %currPath%
:: 写入注册表
:: reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" /v AppInit_DLLs /t REG_SZ /d "%currPath%ExampleDll64.dll" /f
:: reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" /v LoadAppInit_DLLs /t REG_DWORD /d 1 /f
:: copy文件
copy "%currPath%resources\windows\driver\xxxx.sys" C:\Windows\System32\drivers
copy "%currPath%resources\windows\dll\system32\*" C:\Windows\System32
copy "%currPath%resources\windows\dll\sysWOW64\*" C:\Windows\SysWOW64
:: 执行dll
regsvr32 /s "%currPath%resources\windows\ATL\xxxx.dll"
:: 执行inf文件写入启动
rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128 %currPath%resources\windows\driver\xxxxxx.inf
echo e-mbms-client installation complete ...
::重启电脑
shutdown -r -t 3
微笑的java
欢迎关注转发评论点赞沟通,让编码不在孤单。
上一篇: Android webview 加载https网页显示空白
下一篇: webview 显示空白问题