简介
本文是10年前做windows开发时,做安装包是留下的一点关于用NSIS打包安装程序的技术文档。虽然不全面,但是勉强够用。
有兴趣的同学可以到 这里 下载全部脚本(共11个小例子),里面还有一个简单的ppt讲解。写的比较差,勉强可以参考。
实例一 弹出提示框
OutFile "1.exe"
ShowInstDetails show
# create a default section.
section
# create a popup box, with an OK button and the text "Hello world!"
messageBox MB_OK "Hello world!"
sectionEnd
运行结果
点击确定后
实例二 设置变量和显示变量
OutFile "2.exe"
ShowInstDetails show
!define APPNAME "TASS_CSP"
Var /GLOBAL version
Section
DetailPrint ${APPNAME}
StrCpy $version "2.0.0.0"
DetailPrint $version
SectionEnd
运行结果
实例三 函数及控制
OutFile "3.exe"
ShowInstDetails show
Var /GLOBAL str1
Var /GLOBAL str2
Var /GLOBAL strResult
/*
char *para1
char *para2
char *result
*/
Function ConnStrForReg
Pop $1
DetailPrint $1
Pop $0
DetailPrint $0
StrCpy $2 $0$1
Push $2
FunctionEnd
Function ConnStrForVar
StrCpy $strResult $str1$str2
FunctionEnd
section "Main"
StrCpy $str1 "0123456789"
Push $str1
StrCpy $str2 "abcdef"
Push $str2
Call ConnStrForReg
Pop $strResult
DetailPrint '"Reg=====>"$strResult'
StrCpy $str1 "0123456789"
StrCpy $str2 "abcdef"
Call ConnStrForVar
DetailPrint '"Var=====>"$strResult'
sectionEnd
运行结果
实例四 调用动态库功能
OutFile "4.exe"
ShowInstDetails show
Var /GLOBAL strSource
section
StrCpy $strSource "1234567890"
DetailPrint $strSource
md5dll::GetMD5String $strSource
Pop $R0
DetailPrint $R0
StrCpy $0 $strSource
DetailPrint $0
System::Call "user32::MessageBox(i $HWNDPARENT, t r0, t 'Test', i 0)"
sectionEnd
运行结果
点击确定后
实例五 宏
OutFile "5.exe"
ShowInstDetails show
!macro Hello What
DetailPrint "Hello ${What}"
!macroend
Section Test
!insertmacro Hello "World"
!insertmacro Hello "Tree"
!insertmacro Hello "Flower"
SectionEnd
运行结果
实例六 插入欢迎页,licence页,安装页,完成页
OutFile "6.exe"
ShowInstDetails show
!include "MUI.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "lic.txt"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "SimpChinese"
# create a default section.
Section "Main"
# create a popup box, with an OK button and the text "Hello world!"
MessageBox MB_OK "Install section is running!"
SectionEnd