1.制作脚本demo1.nsi
!include "MUI.nsh"
!define MUI_ABORTWARNING # This will warn the user if they exit from the installer.
!insertmacro MUI_PAGE_WELCOME # Welcome to the installer page.
!insertmacro MUI_PAGE_DIRECTORY # In which folder install page.
!insertmacro MUI_PAGE_INSTFILES # Installing page.
!insertmacro MUI_PAGE_FINISH # Finished installation page.
!insertmacro MUI_LANGUAGE "SimpChinese"
Name "MyApp" # Name of the installer (usually the name of the application to install).
Icon "C:\installDic\Installer.ico" # 安装包的图标 128x128
OutFile "MyAppInstaller.exe" # Name of the installer's file.
InstallDir "$PROGRAMFILES\MyApp" # Default installing folder ($PROGRAMFILES is Program Files folder).
ShowInstDetails show # This will always show the installation details.
ShowUnInstDetails show
# In this section add your files or your folders.
# Add your files with "File (Name of the file)", example: "File "$DESKTOP\MyApp.exe"" ($DESKTOP is Desktop folder); or add your folders always with "File (Name of the folder)\*", always add your folders with an asterisk, example: "File /r $DESKTOP\MyApp\*" (this will add its files and (with /r its subfolders)).
Section "install"
SetOutPath $INSTDIR
#你的源码文件路径
File "C:\installDic\*"
writeUninstaller "$INSTDIR\uninstall.exe"
#创建快捷方式
#CreateDirectory "$SMPROGRAMS\MyApp\"
#CreateShortcut "$SMPROGRAMS\MyApp\TXCloudPortal.lnk" $INSTDIR\TXCloudPortal.exe '"$INSTDIR\TXCloudPortal.image"'
#CreateShortcut "$DESKTOP\MSMK LIVE.lnk" $INSTDIR\TXCloudPortal.exe '"$INSTDIR\TXCloudPortal.image"'
#Exec '$INSTDIR\TXCloudPortal.exe "$INSTDIR\TXCloudPortal.image"'
CreateShortCut "$DESKTOP\MSMK.lnk" "$INSTDIR\TXCloudPortal.exe"
SectionEnd
section "uninstall"
# Remove Start Menu launcher
delete "$SMPROGRAMS\MYAPP.lnk"
# Try to remove the Start Menu folder - this will only happen if it is empty
rmDir "$SMPROGRAMS\MYAPP"
# Remove files
delete $INSTDIR\*
# Always delete uninstaller as the last action
delete $INSTDIR\uninstall.exe
# Try to remove the install directory - this will only happen if it is empty
rmDir $INSTDIR
# Remove uninstaller information from the registry
# DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MYAPP"
sectionEnd
.制作脚本demo2.nsi
; Script generated by the HM NIS Edit Script Wizard.
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "TXCloudRoom"
!define PRODUCT_VERSION "3.1.2.0"
!define PRODUCT_PUBLISHER "腾讯云"
!define PRODUCT_WEB_SITE "https://cloud.tencent.com/document/product/454/6555#Windows"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
; MUI 1.67 compatible ------
!include "MUI.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "setup.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; Language Selection Dialog Settings
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
;WorkPlus Setup Script
Unicode true
;Windows Vista系统为应用程序请求权限
RequestExecutionLevel admin
; Welcome page
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY ;调用NSIS选择目录窗口
; License page
;!insertmacro MUI_PAGE_LICENSE "c:\path\to\licence\YourSoftwareLicence.txt"
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
;!define MUI_FINISHPAGE_RUN "$INSTDIR\TXCloudPortal.exe"
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "SimpChinese"
; MUI end ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "TXCloudRoomSetup.exe"
InstallDir "$PROGRAMFILES\TXCloudRoom"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
Section "MainSection" SEC01
CreateDirectory "$INSTDIR\iconengines\"
CreateDirectory "$INSTDIR\imageformats\"
CreateDirectory "$INSTDIR\platforms\"
CreateDirectory "$INSTDIR\translations\"
SetOverwrite on
SetOutPath "$INSTDIR\iconengines\"
File "..\Build\Bin\Release\iconengines\*.dll"
SetOutPath "$INSTDIR\imageformats\"
File "..\Build\Bin\Release\imageformats\*.dll"
SetOutPath "$INSTDIR\platforms\"
File "..\Build\Bin\Release\platforms\*.dll"
SetOutPath "$INSTDIR\translations\"
File "..\Build\Bin\Release\translations\*.qm"
SetOutPath "$INSTDIR"
File "..\Build\Bin\Release\*.dll"
File "..\Build\Bin\Release\*.exe"
SetOutPath "$INSTDIR"
File "vc_redist.x86.exe"
Exec "$INSTDIR\vc_redist.x86.exe /q" ;若不存在,执行静默安装
CreateShortCut "$SMPROGRAMS\TXCloudRoom\${PRODUCT_NAME}.lnk" "$INSTDIR\TXCloudPortal.exe"
WriteRegStr HKCR "TXCloudRoom" "" "TXCloudRoom Protocol"
WriteRegStr HKCR "TXCloudRoom" "URL Protocol" "$INSTDIR\TXCloudRoom.exe"
WriteRegStr HKCR "TXCloudRoom\DefaultIcon" "" "$INSTDIR\TXCloudRoom.exe,1"
WriteRegStr HKCR "TXCloudRoom\shell\open\command" "" '"$INSTDIR\TXCloudRoom.exe","%1"'
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\TXCloudRoom\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\TXCloudRoom\Uninstall.lnk" "$INSTDIR\uninst.exe"
CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\TXCloudPortal.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\TXCloudPortal.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\TXCloudTXCloudPortal.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从你的计算机移除。"
FunctionEnd
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你确实要完全移除 $(^Name) ,其及所有的组件?" IDYES +2
Abort
FunctionEnd
Section Uninstall
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\iconengines\*.dll"
Delete "$INSTDIR\imageformats\*.dll"
Delete "$INSTDIR\platforms\*.dll"
Delete "$INSTDIR\translations\*.qm"
Delete "$INSTDIR\*.exe"
Delete "$INSTDIR\*.dll"
Delete "$SMPROGRAMS\TXCloudRoom\Uninstall.lnk"
Delete "$SMPROGRAMS\TXCloudRoom\Website.lnk"
Delete "$SMPROGRAMS\TXCloudRoom\TXCloudRoom.lnk"
Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
RMDir "$SMPROGRAMS\TXCloudRoom"
RMDir "$INSTDIR\iconengines"
RMDir "$INSTDIR\imageformats"
RMDir "$INSTDIR\platforms"
RMDir "$INSTDIR\translations"
RMDir "$INSTDIR"
DeleteRegKey HKCR "TXCloudRoom"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
2.打开nsis软件导入脚本
学习资料:
https://nsis.sourceforge.io/Category:Tutorials
https://en.wikipedia.org/wiki/Nullsoft_Scriptable_Install_System