1、安装完毕,打开NIS Edit,点击文件,选择新建脚本向导
2、填写应该写的,没有可以为空
3、设置安装语言为“simple chinese”(简体中文),设置安装程序图标(xxx.ico),其余默认即可
4、填写应用程序安装的默认路径,没有授权文件的话置空,有的话百度
5、如图所示
接上一步,点击树形目录,这里选择要发布的exe程序所在的目录,
并选中"包含子目录"以及"单独添加每个文件" ,其余默认
6、默认即可,具体要求自行百度
7、默认即可(当然也可添加一些自定义的自述,如汉化说明等等)
8、在图中只需要修改自定义的卸载程序图标就可以了,其他默认,选择下一步
9、选择“保存脚本”,“转换文件路径到相对路径”,“编译脚本”,然后用NIS Edit进行编译,执行打包过程,最后生成成功,点击Setup.exe运行即可安装。
注意:如果想在程序安装的时候需要进行.NET FRAMEWORK的判断及静默安装,则需要在nsi脚本中添加如下代码:
Function GetNetFrameworkVersion
;获取.Net Framework版本支持
Push $1
Push $0
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Install"
ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Version"
StrCmp $0 1 KnowNetFrameworkVersion +1
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" "Install"
ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" "Version"
StrCmp $0 1 KnowNetFrameworkVersion +1
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "InstallSuccess"
ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "Version"
StrCmp $0 1 KnowNetFrameworkVersion +1
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Install"
ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Version"
StrCmp $1 "" +1 +2
StrCpy $1 "2.0.50727.832"
StrCmp $0 1 KnowNetFrameworkVersion +1
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Install"
ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Version"
StrCmp $1 "" +1 +2
StrCpy $1 "1.1.4322.573"
StrCmp $0 1 KnowNetFrameworkVersion +1
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0" "Install"
ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0" "Version"
StrCmp $1 "" +1 +2
StrCpy $1 "1.0.3705.0"
StrCmp $0 1 KnowNetFrameworkVersion +1
StrCpy $1 "not .NetFramework"
KnowNetFrameworkVersion:
Pop $0
Exch $1
FunctionEnd
其他:安装程序是判断当前电脑是否已安装程序,是否卸载
Var UNINSTALL_PROG
Var OLD_VER
Var OLD_PATH
Function .onInit
ClearErrors
ReadRegStr $UNINSTALL_PROG ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "UninstallString"
IfErrors done
ReadRegStr $OLD_VER ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "DisplayVersion"
MessageBox MB_YESNOCANCEL|MB_ICONQUESTION \
"检测到本机已经安装了 ${PRODUCT_NAME} $OLD_VER。\
$\n$\n是否先卸载已安装的版本?" \
/SD IDYES \
IDYES uninstall \
IDNO done
Abort
uninstall:
StrCpy $OLD_PATH $UNINSTALL_PROG -10
ExecWait '"$UNINSTALL_PROG" /S _?=$OLD_PATH' $0
DetailPrint "uninst.exe returned $0"
Delete "$UNINSTALL_PROG"
RMDir $OLD_PATH
done:
FunctionEnd
以上代码可以放在Section "主程序必选" SEC01之前,然后在进行编译脚本。
其他: 如果要运行批处理,且需要在安装路径运行,可添加以下代码:
Section "生成机器码"
#SetOutPath "$INSTDIR\runHID.bat"
#nsExec::Exec "$INSTDIR\runHID.bat"
SetOutPath '$INSTDIR'
ExecWait '$INSTDIR/runHID.bat'
SectionEnd