nsis安装程序例子

;安装名称
!define PRODUCT_NAME "Web应用防火墙"
;VIAddVersionKey CompanyName "Apache Software Foundation"
;软件版本
!define PRODUCT_VERSION "6.0.14"
;信息
!define PRODUCT_PUBLISHER "hexun, WangChong."
;官网
!define PRODUCT_WEB_SITE http://hi.baidu.com/jonw000
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\firewall.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

;声明ini文件,便于nsis快速找到文件
reservefile "ini\port.ini"
reservefile "ini\resSystem.ini"
ReserveFile "${NSISDIR}\Plugins\InstallOptions.dll"
;包含头文件

; MUI 1.67 compatible ------
!include "MUI.nsh"
!include "MUI2.nsh"
!include "WordFunc.nsh"
!include "Sections.nsh"
!include "WinMessages.nsh"
!include "LogicLib.nsh"

!include InstallOptions.nsh
!include LangFile.nsh
!include WinMessages.nsh


;在安装过程中按“取消”的话,会弹出是否终止安装的确认窗口,
;去掉下的 !define MUI_ABORTWARNING,按“取消”则会直接退出呢?
!define MUI_ABORTWARNING
;安装图标
!define MUI_ICON "ico\orange-install.ico"
;卸载图标
!define MUI_UNICON "ico\modern-uninstall-colorful.ico"
;将hexun.bmp文件放到安装界面的右上角
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_RIGHT
!define MUI_HEADERIMAGE_BITMAP "bmp\hexun.bmp"
; 欢迎页
page custom unprogram
;定一品牌链接字体
BrandingText "武漢和迅計算机工程有限公司"
;设置欢迎业标题字体大小
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ChageFONT
;改变品牌链接
!define MUI_CUSTOMFUNCTION_GUIINIT onGUIInit
;改变欢迎业左边图片
!define MUI_WELCOMEFINISHPAGE_BITMAP "bmp\orange.bmp"
;欢迎页

;!define MUI_WELCOMEPAGE_TEXT "hjk"
!insertmacro MUI_PAGE_WELCOME
;许可证
!insertmacro MUI_PAGE_LICENSE "说明书.txt"
;安装路经
!insertmacro MUI_PAGE_DIRECTORY
;获得端口
page custom getPort
;安装文件
!insertmacro MUI_PAGE_INSTFILES
;安装完成页面
!insertmacro MUI_PAGE_FINISH


;安装卸载过程页面
;卸载欢迎页

!insertmacro MUI_UNPAGE_WELCOME
;卸载配置
!insertmacro MUI_UNPAGE_CONFIRM
;卸载信息
!insertmacro MUI_UNPAGE_INSTFILES
; 卸载完成页面
!insertmacro MUI_UNPAGE_FINISH
page custom res
;安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese" ;"English"


; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Web应用防火墙.exe"
InstallDir "$PROGRAMFILES"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show


Function .onInit
InitPluginsDir
;如果要做多语言界面,可以在这里根据具体操作系统语言来更改ini的文件名
File "/oname=$PLUGINSDIR\resSystem.ini" "ini\resSystem.ini"
File "/oname=$PLUGINSDIR\port.ini" "ini\port.ini"

;禁止多个安装程序
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "firewall") i .r1 ?e'
Pop $R0

StrCmp $R0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION "安装程序已经在运行。"
Abort
FunctionEnd

;获得tomcat端口的方法
Function getport
;给port.ini文本框赋值
;!insertmacro MUI_INSTALLOPTIONS_WRITE "port.ini" "Field 2" "State" "8080"
;弹出port.ini的窗口
InstallOptions::dialog "$PLUGINSDIR\port.ini"
;获得port.ini的值信息
!insertmacro MUI_INSTALLOPTIONS_READ $3 "port.ini" "Field 2" "State"
FunctionEnd


;设置欢迎页的标题字的大小
Function ChageFONT
GetDlgItem $2 $MUI_HWND 1201
createFont $1 "Tahoma" "12" "700"
SendMessage $2 ${WM_SETFONT} $1 2
FunctionEnd

;判断是此程序是否已经安装
var rt
function unprogram

ReadRegStr $rt HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\firewall.exe" "has"
IfErrors +4
Goto +1
MessageBox MB_OK "web 应用防火墙已经存在,若要重新安装,请先卸载"
quit
functionend

;对话框,重启计算机
Function res
MessageBox MB_ICONQUESTION|MB_YESNO "安装成功!$\n$\r须重启计算机后才能生效!$\n$\r是否立即重启?" idno +2
reboot
quit
; Abort
FunctionEnd

;品牌字超链接
Function onGUIInit
BrandingURL::Set /NOUNLOAD "200" "0" "0" "http://hi.baidu.com/jonw000"
FunctionEnd

## Unload the plugin.
Function .onGUIEnd
BrandingURL::Unload
FunctionEnd


;安装区段
Section "modify web.xml file" SEC11

IfFileExists "$INSTDIR\conf\web.xml" +3
goto +1
Abort "Tomcat 路经不正确,不能安装" ;MessageBox MB_OK "Tomcat 路经不正确"
;篡改XML文件
nsisXML::create
nsisXML::load "$INSTDIR\conf\web.xml"
nsisXML::select "/web-app"

nsisXML::createElement "filter"
nsisXML::appendChild
StrCpy $1 $2

nsisXML::createElement "filter-name"
nsisXML::setText "fireWallFilter"
nsisXML::appendChild

;nsisXML::setText "$\n"

nsisXML::createElement "filter-class"
nsisXML::setText "org.hexun.wangchong.admin.filters.FireWallFilter"
nsisXML::appendChild

;nsisXML::setText "$\n"

nsisXML::createElement "init-param"
nsisXML::appendChild
StrCpy $1 $2

;nsisXML::setText "$\n"

nsisXML::createElement "param-name"
nsisXML::setText "encoding"
nsisXML::appendChild

;nsisXML::setText "$\n"

nsisXML::createElement "param-value"
nsisXML::setText "UTF-8"
nsisXML::appendChild

; nsisXML::setText "$\n"

nsisXML::select "/web-app"

nsisXML::createElement "filter-mapping"
nsisXML::appendChild
StrCpy $1 $2

; nsisXML::setText "$\n"

nsisXML::createElement "filter-name"
nsisXML::setText "fireWallFilter"
nsisXML::appendChild

; nsisXML::setText "$\n"

nsisXML::createElement "url-pattern"
nsisXML::setText "/*"
nsisXML::appendChild

nsisXML::save "$INSTDIR\conf\web.xml"

;!insertmacro MUI_PAGE_DIRECTORY
/*
<filter>
<filter-name>fireWallFilter</filter-name>
<filter-class>org.hexun.wangchong.admin.filters.FireWallFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>


<filter-mapping>
<filter-name>fireWallFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
*/
SetAutoClose false
SectionEnd


Section "copy dll to jre" SEC00
SetOutPath "$INSTDIR\bin"
SetOverwrite try
File /r "sysDll\*.*"
CreateShortCut "$SMPROGRAMS\bin\*" "$PROGRAMFILES\sysDll\*"
SetAutoClose false
SectionEnd
;copy验证文件

Section "copy validator xml file" SEC01
SetOutPath "$INSTDIR\firewall"
SetOverwrite try
File /r "configXML\*.*"

CreateShortCut "$SMPROGRAMS\firewall\*" "$PROGRAMFILES\configXML\*"

SetAutoClose false
SectionEnd


Section "copy managerTomcat file" SEC02
SetOutPath "$INSTDIR\webapps\managerTomcat"
SetOverwrite try
File /r "managerTomcat\*.*"
;CreateDirectory "$SMPROGRAMS\webapps\managerTomcat"
detailprint "正在复制文件到webApps......."
CreateShortCut "$SMPROGRAMS\webapps\managerTomcat\*" "$PROGRAMFILES\managerTomcat\*"
;CreateShortCut "$SMPROGRAMS\firewall\web.xml" "$SMPROGRAMS\conf\web.xml"
sleep 250
SetAutoClose false
SectionEnd
;copy jar文件
Section "copy jar file" SEC03
SetOutPath "$INSTDIR\lib"
SetOverwrite try
File /r "jar\*.*"
detailprint "正在复制jar包到lib......."
CreateShortCut "$SMPROGRAMS\lib\*" "$PROGRAMFILES\jar\*"
sleep 250
SetAutoClose false
SectionEnd

;创建开始菜单下的快捷方式
Section "copy icon action and un file Uninstall" SEC04
SetOutPath "$PROGRAMFILES\Web应用防火墙"
SetOverwrite try
detailprint "添加到开始菜单下的快捷方式......."
sleep 250

detailprint "开始菜单下创建Web应用防火墙......."
CreateDirectory "$SMPROGRAMS\Web应用防火墙"
sleep 250
detailprint "Web应用防火墙添加防火墙图标......."
CreateShortCut "$SMPROGRAMS\Web应用防火墙\防火墙.lnk" "http://localhost:$3/managerTomcat"

sleep 250

SetAutoClose false
SectionEnd
/*
;创建桌面快捷方式
Section "copy icon action and un file Uninstall" SEC34
SetOutPath "$INSTDIR"
SetOverwrite try
detailprint "添加到桌面面快捷方式......."
CreateShortCut "$DESKTOP\防火墙.lnk" "http://localhost:$3/managerTomcat"
sleep 250
SetAutoClose false
SectionEnd
*/


;创建开始菜单下的快捷方式
Section -AdditionalIcons SEC44
SetOutPath "$PROGRAMFILES\Web应用防火墙"
SetOverwrite try
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
; WriteIniStr "$INSTDIR\我们公司.url" "InternetShortcut" "URL" "http://localhost:$3/managerTomcat"
detailprint "Web应用防火墙添加防火墙图标......."
;CreateShortCut "$SMPROGRAMS\Web应用防火墙\我们公司.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\Web应用防火墙\我们公司.lnk" "http://www.hexun.com.cn"
CreateShortCut "$SMPROGRAMS\Web应用防火墙\卸载.lnk" "$INSTDIR\uninst.exe"
sleep 500
Delete "$SMPROGRAMS\lib"
Delete "$SMPROGRAMS\firewall"
Delete "$SMPROGRAMS\bin"
SectionEnd
;设置环境变量
Section "set Environment" SEC05
;ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MANAGERTOMCAT"
detailprint "设置环境变量......."
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MANAGERTOMCAT" "$INSTDIR"
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment"
sleep 500
SectionEnd

Section "WriteReg firewall"
WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\firewall.exe" "has" "$INSTDIR"
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$0;%SystemRoot%\system32"
SetAutoClose false
SectionEnd

;写入注册表
Section -Post
detailprint "正在写入注册表......."
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\firewall.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\managerTomcat\WebRoot\main.html"
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}"
sleep 500
SectionEnd


;卸载完成后
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从你的计算机移除。"
FunctionEnd
;卸载对话框
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你确实要完全移除 $(^Name) ,其及所有的组件?" IDYES +2
Abort
FunctionEnd


;卸载
Section Uninstall

detailprint "正在删除lib文件夹下内容......."

Delete "$INSTDIR\lib\Access_JDBC30.jar"
IfFileExists "$INSTDIR\lib\Access_JDBC30.jar" +2
goto +3
MessageBox MB_OK "文件正在使用,卸载失败,请先关闭相关服务,在进行卸载"
quit
Delete "$INSTDIR\lib\catalina-admin.jar"
IfFileExists "$INSTDIR\lib\catalina-admin.jar" +2
goto +3
MessageBox MB_OK "文件正在使用,卸载失败,请先关闭相关服务,在进行卸载"
quit
Delete "$INSTDIR\lib\commons-beanutils.jar"
IfFileExists "$INSTDIR\lib\Access_JDBC30.jar" +2
goto +3
MessageBox MB_OK "文件正在使用,卸载失败,请先关闭相关服务,在进行卸载"
quit
Delete "$INSTDIR\lib\commons-collections.jar"
IfFileExists "$INSTDIR\lib\commons-collections.jar" +2
goto +3
MessageBox MB_OK "文件正在使用,卸载失败,请先关闭相关服务,在进行卸载"
quit
Delete "$INSTDIR\lib\commons-digester-1.7.jar"
IfFileExists "$INSTDIR\lib\commons-digester-1.7.jar" +2
goto +3
MessageBox MB_OK "文件正在使用,卸载失败,请先关闭相关服务,在进行卸载"
quit
Delete "$INSTDIR\lib\commons-logging.jar"
IfFileExists "$INSTDIR\lib\commons-logging.jar" +2
goto +3
MessageBox MB_OK "文件正在使用,卸载失败,请先关闭相关服务,在进行卸载"
quit
Delete "$INSTDIR\lib\dom4j-1.6.1.jar"
IfFileExists "$INSTDIR\lib\dom4j-1.6.1.jar" +2
goto +3
MessageBox MB_OK "文件正在使用,卸载失败,请先关闭相关服务,在进行卸载"
quit
Delete "$INSTDIR\lib\firewall.jar"
IfFileExists "$INSTDIR\lib\firewall.jar" +2
goto +3
MessageBox MB_OK "文件正在使用,卸载失败,请先关闭相关服务,在进行卸载"
quit
Delete "$INSTDIR\lib\struts.jar"
IfFileExists "$INSTDIR\lib\struts.jar" +2
goto +3
MessageBox MB_OK "文件正在使用,卸载失败,请先关闭相关服务,在进行卸载"
quit
sleep 500

detailprint "还原web.xml文件......."
;Delete "$INSTDIR\conf\web.xml"
nsisXML::create /NOUNLOAD
nsisXML::load /NOUNLOAD "$INSTDIR\conf\web.xml"
nsisXML::select /NOUNLOAD '/web-app/filter[@xmlns=""]'
${If} $2 == 0
goto +11
${endif}
nsisXML::parentNode /NOUNLOAD
nsisXML::removeChild /NOUNLOAD
nsisXML::save "$INSTDIR\conf\web.xml"
nsisXML::create /NOUNLOAD
nsisXML::load /NOUNLOAD "$INSTDIR\conf\web.xml"
nsisXML::select /NOUNLOAD '/web-app/filter-mapping[@xmlns=""]'
nsisXML::parentNode /NOUNLOAD
nsisXML::removeChild /NOUNLOAD
nsisXML::save "$INSTDIR\conf\web.xml"
sleep 500
detailprint "正在删除防火墙配置文件......."
Delete "$INSTDIR\firewall\*"
sleep 500

detailprint "正在删除firewall文件夹......."
RMDir "$INSTDIR\firewall"
sleep 500

detailprint "正在删除managerTomcat下的文件......."
Delete "$INSTDIR\webapps\managerTomcat\*"
sleep 500

detailprint "正在删除managerTomcat文件夹......."
Delete "$INSTDIR\webapps\managerTomcat\*"
RMDir /r "$INSTDIR\webapps\managerTomcat"
sleep 500

detailprint "正在公司主页......."
Delete "$INSTDIR\Web应用防火墙"
Delete "$INSTDIR\Web应用防火墙.lnk"
Delete "$INSTDIR\uninst.exe"

sleep 500


detailprint "正在删除相关DLL......."

Delete "$INSTDIR\bin\mySystemDll.dll"
Delete "$INSTDIR\bin\MyDll.dll"
Delete "$INSTDIR\bin\ICE_JNIRegistry.dll"
Delete "$INSTDIR\bin\fireWallValidator.dll"

sleep 500


detailprint "正在清理注册表......."
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
sleep 500

detailprint "正在删除相关环境变量......."
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MANAGERTOMCAT" ""

ReadRegStr $R0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
${WordReplace} $R0 ";%SystemRoot%\system32" "" "+" $R1
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R1"
/*
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$0;%SystemRoot%\system32"
*/
sleep 500

detailprint "正在删除开始菜单下的快捷方式......."
Delete "$SMPROGRAMS\Web应用防火墙\*"
sleep 500
detailprint "正在删除开始菜单下的文件夹......."
RMDir "$SMPROGRAMS\Web应用防火墙"
/*
Delete "$SMPROGRAMS\lib"
Delete "$SMPROGRAMS\firewall"
Delete "$SMPROGRAMS\bin"
*/
sleep 500
SetAutoClose true
SectionEnd
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值