笔记我使用 NSIS 製作 Windows 安装档的过程

NSIS (Nullsoft Scriptable Install System) 是一个建立安装档非常好用且免费的软体。

有鉴于资讯的发展日新月异,在进入主题之前,我先注明一下本次笔记内所使用的软硬体概况:

iMac Retina 4K,21.5 英寸,2017,3.4GHz CPU,8GB 2400MHz DDR4 RAM,120 GB USBHDDWindows 10 家用版 (版本 1903)NSIS 3.07

使用前我试着翻阅中英文的说明,不得不说,这些说明反而让人望之却步,正当我苦恼之际,在软体的介面上,看到「Example scripts」几个字,顺势点进去之后,我分别开启 example1 与 example2 这 2 个档案,观察一下之后,就直接拿 example2 来改,原因是 example2 把 Uninstaller 的写法直接放进来,而这正是我需要的,服用的方式,也算容易,用 Notepad++ 打开后,我就用取代的方式,把关键字「Example2」换成我要安装的应用程式名称,除此之外,还走过下面几个步骤:

因为要打包的程式,在执行上的需求,我也就把 AccessControl plug-in 安装进来。

本以为,直接解压到 NSIS 的安装目录就可以,结果…,因为编译错误的关係,我发现要自己去把「i386-ansi」与「i386-unicode」里面的 AccessControl.dll 分别移到「x86-ansi」与「x86-unicode」(这支 AccessControl.dll 在两个夹子的名字都一样,因此,移动的时候,要特别注意别搞错)。

再经过几次调校后,就成功打包起来。

可以安装是一定要的。

然后,可以全权读取与写入,所以,程式的执行上,也没有什么问题。

最后,跑一下 Uninstaller,确认可以移除档案、资料夹与捷径。

最后,考虑到安全性的问题,我就不提供 .nsi 的 Scripts 档下载,直接贴出来给大家参考,如果也刚好符合您大致上的需求,也可以直接複製去服用。

; DNW.nsi;; This script is based on example1.nsi, but it remember the directory, ; has uninstall support and (optionally) installs start menu shortcuts.;; It will install DNW.nsi into a directory that the user selects.;; See install-shared.nsi for a more robust way of checking for administrator rights.; See install-per-user.nsi for a file association example.;--------------------------------; The name of the installerName "DNW"; The file to writeOutFile "DNWInstaller.exe"; Request application privileges for Windows Vista and higherRequestExecutionLevel admin; Build Unicode installerUnicode True; The default installation directoryInstallDir $PROGRAMFILES\DNW; Registry key to check for directory (so if you install again, it will ; overwrite the old one automatically)InstallDirRegKey HKLM "Software\DNW" "Install_Dir";--------------------------------; PagesPage componentsPage directoryPage instfilesUninstPage uninstConfirmUninstPage instfiles;--------------------------------; The stuff to installSection "DNW (required)"  SectionIn RO    ; Set output path to the installation directory.  SetOutPath $INSTDIR    ; Put file there  File "DNW.exe"  File "makeData.exe"    ; Write the installation path into the registry  WriteRegStr HKLM SOFTWARE\DNW "Install_Dir" "$INSTDIR"    ; Write the uninstall keys for Windows  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DNW" "DisplayName" "DNW"  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DNW" "UninstallString" '"$INSTDIR\uninstall.exe"'  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DNW" "NoModify" 1  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DNW" "NoRepair" 1  WriteUninstaller "$INSTDIR\uninstall.exe"  SectionEndSection  SetOutPath "$INSTDIR\data"  SetOverwrite on  File /nonfatal /r "$data\*.*"  AccessControl::GrantOnFile "$INSTDIR\data" "(S-1-1-0)" "FullAccess"  AccessControl::GrantOnFile "$INSTDIR\data" "(S-1-5-32-545)" "FullAccess"# Give all authentificated users (BUILTIN\Users) full access on# the registry key HKEY_LOCAL_MACHINE\Software\DNW  AccessControl::GrantOnRegKey \    HKLM "Software\DNW\data" "(BU)" "FullAccess"  Pop $0SectionEnd; Optional section Section "Start Menu Shortcuts"  CreateDirectory "$SMPROGRAMS\DNW"  CreateShortcut "$SMPROGRAMS\DNW\Uninstall.lnk" "$INSTDIR\uninstall.exe"  SetOutPath "$INSTDIR"  CreateShortcut "$SMPROGRAMS\DNW\DNW.lnk" "$INSTDIR\DNW.exe"SectionEnd; Optional sectionSection "Desktop Shortcut"  SetOutPath "$INSTDIR"  CreateShortcut "$DESKTOP\DNW.lnk" "$INSTDIR\DNW.exe"SectionEnd;--------------------------------; UninstallerSection "Uninstall"    ; Remove registry keys  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DNW"  DeleteRegKey HKLM "SOFTWARE\DNW"  ; Remove files and uninstaller  Delete "$INSTDIR\*.*"  Delete "$INSTDIR\data\*.*"  ; Remove shortcuts, if any  Delete "$SMPROGRAMS\DNW\*.lnk"  Delete "$DESKTOP\DNW.lnk"  ; Remove directories  RMDir "$INSTDIR\DNW\data"  RMDir "$INSTDIR\DNW"  RMDir "$INSTDIR"  RMDir /r "$INSTDIR"SectionEnd

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章