-
配置nisi脚本以适应jdk、tomcat、mysql和redis需
资源介绍
一.环境变量配置
; 定义系统环境变量的 注册表key值
!define WriteEnvStr_RegKey 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
;设置环境变量
Function "regExpandStr"
SetOverwrite ifnewer
;设置jdk环境变量
WriteRegExpandStr ${WriteEnvStr_RegKey} "JAVA_HOME" "$INSTDIR\jdk1.8.0_131"
;设置CATALINA_DIR
WriteRegExpandStr ${WriteEnvStr_RegKey} "CATALINA_DIR" "$INSTDIR\tomcat\bin"
;设置CATA_LINA
WriteRegExpandStr ${WriteEnvStr_RegKey} "CATA_LINA" "$INSTDIR\tomcat"
;设置path
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$0;C:\windows\system32;$INSTDIR\redis;$INSTDIR\mysql\bin;$INSTDIR\Java\jdk1.8.0_131\bin;"
#第一次是使环境变量修改对其他进程有效;刷新环境变量
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
SetOverwrite on
functionend
;注册服务
Function "installService"
detailprint "------------------------------------install tomcat Service..."
Sleep 2000
SetOutPath "$INSTDIR\tomcat\bin"
nsExec::Exec 'cmd /c service install'
nsExec::Exec 'cmd /c sc config tomcat8 start= auto' ;设置服务自动开启
detailprint "------------------------------------install tomcat Service success..."
detailprint "install mysql Service..."
Sleep 2000
SetOutPath "$INSTDIR\mysql\bin"
nsExec::Exec 'cmd /c $INSTDIR\mysql\bin\mysqld.exe" -install Mysql --defaults-file="$INSTDIR\\mysql\\my.ini'
detailprint "install mysql Service success..."
detailprint "------------------------------------install redis Service..."
Sleep 2000
SetOutPath "$INSTDIR\redis"
nsExec::Exec 'cmd /c redis-server --service-install redis.windows.conf'
detailprint "install redis Service success..."
functionend
; 启动服务
Function "startService"
detailprint "------------------------------------start tomcat..."
nsExec::Exec 'cmd /c sc start Tomcat8'
detailprint "------------------------------------start tomcat success..."
detailprint "------------------------------------start mysql..."
nsExec::Exec 'cmd /c sc start mysql'
detailprint "------------------------------------start MySQL success..."
detailprint "------------------------------------start redis..."
;nsExec::Exec 'cmd /c sc redis-server --service-start --service-name redis'
detailprint "------------------------------------start redis success..."
functionend
;停止服务
Function "un.stopService"
detailprint "正在停止tomcat服务......."
nsExec::Exec 'cmd /c sc stop tomcat8'
detailprint "停止tomcat服务成功......."
detailprint "正在停止mysql服务......."
nsExec::Exec 'cmd /c sc stop mysql'
detailprint "停止mysql服务成功......."
detailprint "正在停止redis服务......."
nsExec::Exec 'cmd /c sc redis-server --service-stop --service-name redis'
detailprint "停止redis服务成功......."
functionend
;删除服务
Function "un.uninstService"
detailprint "正在卸载tomcat服务......."
nsExec::Exec 'cmd /c sc delete tomcat8'
detailprint "卸载tomcat服务成功......."
detailprint "正在卸载mysql服务......."
nsExec::Exec 'cmd /c sc delete mysql'
detailprint "卸载mysql服务成功......."
detailprint "正在卸载redis服务......."
nsExec::Exec 'cmd /c sc delete redis'
detailprint "卸载redis服务成功......."
functionend
;清空环境变量
Function "un.emptyRegExpandStr"
#删除 系统环境变量JAVA_HOME 和 CATALINA_HOME
#卸载的时候必须设置JAVA_HOME 和 CATALINA_HOME两个环境系统变量为空,或者删除这两个系统变量。否则会出现NSIS选择系统变量的错误(NSIS会自动选择之前有值的系统变量,而不是选择当前刚设置的系统变量)
detailprint "正在删除相关环境变量......."
functionend
二.校验mac地址
#序列号 校验页面
Page custom check_serial_number
Var "MacAddress"
Function check_serial_number
Call .GetMacAddress
#MessageBox MB_OK '当前机器Mac地址为:$MacAddress'
${if} $MacAddress == '00-50-56-C0-00-08' ${OrIf} $MacAddress == '00-50-56-C0-00-081'
#MessageBox MB_OK '已授权'
${Else}
MessageBox MB_OK '未授权,请联系经销商并授权!'
;SendMessage $HWNDPARENT 0x408 3 0 #页面跳转
Call onClickClose
${EndIf}
FunctionEnd
#获取主机MAC地址
Function .GetMacAddress
System::Call Iphlpapi::GetAdaptersInfo(i,*i.r0)
System::Alloc $0
Pop $1
System::Call Iphlpapi::GetAdaptersInfo(ir1r2,*ir0)i.r0
StrCmp $0 0 0 finish
loop:
StrCmp $2 0 finish
System::Call '*$2(i.r2,i,&t260;.s,&t132;.s,i.r5)i.r0' ;Unicode版将t改为m
IntOp $3 403 + $5
StrCpy $6 ""
${For} $4 404 $3
IntOp $7 $0 + $4
System::Call '*$7(&i1;.r7)'
IntFmt $7 "X" $7
StrCpy $6 "$6$7"
StrCmp $4 $3 +2
StrCpy $6 "$6-"
${Next}
StrCpy $MacAddress $6
Goto loop
finish:
System::Free $1
FunctionEnd
三.关闭按钮功能
;点击右上角关闭按钮
Function onClickClose
FindProcDLL::FindProc "${PRODUCT_NAME}.exe"
Sleep 500
Pop $R0
${If} $R0 != 0
KillProcDLL::KillProc "${PRODUCT_NAME}.exe"
${EndIf}
FunctionEnd