杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2294|回复: 0

NSIS一键安装网站环境及部署网站

[复制链接]
发表于 2019-3-1 17:24:40 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. ;项目: 智慧校园云平台
  2. ;时间: 2014年7月16日
  3. ;作者: Kan Lau
  4. ; 该脚本使用 HM VNISEdit 脚本编辑器向导产生


  5. ; 安装程序初始定义常量
  6. !define PRODUCT_NAME "金太阳智慧校园云平台教育软件"
  7. !define PRODUCT_EN_NAME "金太阳智慧校园云平台教育软件"
  8. !define PRODUCT_PROC_NAME "KSWebInstraller.exe"
  9. !define PRODUCT_VERSION "1.1"
  10. !define PRODUCT_PUBLISHER "深圳市方直科技股份有限公司"
  11. !define PRODUCT_WEB_SITE "http://www.kingsunsoft.com"
  12. !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
  13. !define PRODUCT_UNINST_ROOT_KEY "HKLM"
  14. ###############################
  15. #打包时,需要修改此处版本号!
  16. ###############################
  17. #安装界面显示版本号,必须为X.X的格式(否则版本号比较会失败)
  18. #安装程序信息描述版本号 必须为 X.X.X.X
  19. !define _PRODUCTVER "1.1.0.0"
  20. !define _PRODUCTDES "金太阳智慧校园云平台教育软件"


  21. !define MUI_WELCOMEFINISHPAGE_BITMAP "res\left.bmp" ; 左侧标题位图


  22. !define MUI_HEADERIMAGE
  23. !define MUI_HEADERIMAGE_RIGHT ; 将页眉图片显示到右边,默认为左边
  24. !define MUI_HEADERIMAGE_BITMAP "res\header-r.bmp" ; 设置标题图片,BMP位图格式.大小为 150 x 57
  25. SetCompressor lzma


  26. ; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
  27. !include "MUI.nsh"
  28. !include "WinVer.nsh"
  29. !include "UAC.nsh"
  30. ; ------ 添加判断操作系统的头函数 ------
  31. !include "x64.nsh"


  32. ; ------ 添加字符串处理的头函数 ------
  33. !include WordFunc.nsh
  34. !include "LogicLib.nsh"


  35. ; MUI 预定义常量
  36. !define MUI_ABORTWARNING
  37. !define MUI_ICON "res\inst.ico"
  38. !define MUI_UNICON "res\uninst.ico"


  39. ; 欢迎页面
  40. !insertmacro MUI_PAGE_WELCOME
  41. ; 安装目录选择页面
  42. !insertmacro MUI_PAGE_DIRECTORY
  43. ; 许可协议页面
  44. !insertmacro MUI_PAGE_LICENSE "F:\Work file\2014\智慧校园安装包\Nsis\license.rtf"


  45. ; 安装过程页面
  46. !insertmacro MUI_PAGE_INSTFILES
  47. ; 定义安装界面
  48. !define MUI_FINISHPAGE_RUN
  49. ; 安装完成页面
  50. !define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
  51. ;!insertmacro MUI_PAGE_INSTFILES
  52. ;!define MUI_PAGE_CUSTOMFUNCTION_PRE LaunchLink
  53. !insertmacro MUI_PAGE_FINISH


  54. ; 安装卸载过程页面
  55. !insertmacro MUI_UNPAGE_INSTFILES


  56. ; 安装界面包含的语言设置
  57. !insertmacro MUI_LANGUAGE "SimpChinese"


  58. VIProductVersion "${_PRODUCTVER}"
  59. VIAddVersionKey /LANG=2052 "ProductName" "${_PRODUCTDES}"
  60. VIAddVersionKey /LANG=2052 "CompanyName" "深圳市方直科技股份有限公司"
  61. VIAddVersionKey /LANG=2052 "FileDescription" "${_PRODUCTDES}"
  62. VIAddVersionKey /LANG=2052 "FileVersion" "${_VERSION}"
  63. VIAddVersionKey /LANG=2052 "LegalCopyright" "Copyright (C) Kingsunsoft. 保留所有权利。"
  64. ; 安装预释放文件
  65. !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
  66. ; ------ MUI 现代界面定义结束 ------


  67. Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
  68. OutFile "KSWebInstraller.exe"
  69. InstallDir "$PROGRAMFILES\方直金太阳\金太阳智慧校园平台"
  70. ShowInstDetails show
  71. ShowUnInstDetails show
  72. BrandingText "方直金太阳软件"


  73. Var local_ip          ;运行安装程序的电脑IP
  74. Var ports_firstports  ;循环判断空闲端口的第一个端口号
  75. Var ports_value       ;端口值
  76. Var free_ports        ;空闲端口
  77. Var version_number    ;版本号
  78. Var XML_PATH          ;配置文件路径
  79. Var Index             ;生成网站的网站ID
  80. Var path              ;安装程序所在的路径,用于设置安装完IIS后,写入注册表,达到重启一次能自动运行安装程序的作用
  81. Var update_path       ;安装升级服务所在的路径
  82. Var empty
  83. ;----------------------------------------------------请求UAC权限---------------------------------
  84. !macro Init thing
  85. uac_tryagain:
  86. !insertmacro UAC_RunElevated
  87. ${Switch} $0
  88. ${Case} 0
  89. ${IfThen} $1 = 1 ${|} Quit ${|} ;we are the outer process, the inner process has done its work, we are done
  90. ${IfThen} $3 <> 0 ${|} ${Break} ${|} ;we are admin, let the show go on
  91. ${If} $1 = 3 ;RunAs completed successfully, but with a non-admin user
  92. ;MessageBox mb_YesNo|mb_IconExclamation|mb_TopMost|mb_SetForeground "This ${thing} requires admin privileges, try again" /SD IDNO IDYES uac_tryagain IDNO 0
  93. ${EndIf}
  94. ;fall-through and die
  95. ${Case} 1223
  96. ;MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "This ${thing} requires admin privileges, aborting!"
  97. Quit
  98. ${Case} 1062
  99. ;MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Logon service not running, aborting!"
  100. ;Quit
  101. ${Default}
  102. ;MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate, error $0"
  103. ;Quit
  104. ${EndSwitch}


  105. SetShellVarContext current
  106. !macroend
  107. ;-----------------------------------------------------------------------------------------------


  108. Function .onInit
  109. StrCpy $version_number "1.1"
  110. System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${PRODUCT_NAME} ${PRODUCT_VERSION}") i .r1 ?e' ;判断是否已启动安装程序
  111. Pop $R0
  112. StrCmp $R0 0 +3
  113.    MessageBox MB_OK|MB_ICONEXCLAMATION "安装程序已经在运行。"
  114.    Abort
  115.    
  116. ${If} ${IsWinXP}
  117. ${OrIf} ${IsWinVista}
  118. MessageBox MB_OK "暂不支持XP或Vista系统!"
  119. Quit
  120. ${EndIf}


  121. ClearErrors
  122. ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\InetStp" "MajorVersion"
  123. ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\InetStp" "MinorVersion"
  124. IfErrors 0 NextFunction
  125.   ${If} ${RunningX64}
  126.   DetailPrint "暂不支持64位下的IIS安装,请安装完IIS后再运行此安装包"
  127. Quit
  128. ${EndIf}


  129.    NextFunction:

  130. ;获取安装程序所在路径
  131.   System::Call 'kernel32::GetCurrentDirectory(i 1024,t .R8)'
  132.   strCpy $path $R8
  133.   ReadRegDWORD $0 HKLM "SOFTWARE\WisdomCampus" "KSWebVersion"
  134.   StrCpy $empty ""
  135.   StrCmp $0 $empty notFound
  136.   ${If} $0 < "$version_number"
  137.   MessageBox MB_OK|MB_ICONEXCLAMATION "检测到当前系统已安装较低版本网站,请先执行Uninstall卸载后再执行此安装"
  138.   Quit
  139.   ${Else}
  140.   MessageBox MB_OK|MB_ICONEXCLAMATION "检测到当前系统已安装相同版本或更高版本的网站"
  141.   Quit
  142. ${EndIf}
  143. notFound:
  144. FunctionEnd


  145. Section "MainSection" SEC01
  146.   SetOutPath "$INSTDIR"
  147.   SetOverwrite ifnewer
  148. ;获取安装程序所在路径
  149. ; File /r "F:\Work file\2014\Nsis\TestWeb\*.*" ;添加网站
  150. ; File /r "F:\Work file\2014\智慧校园安装包\WebSite\*.*"
  151. ; File "F:\Work file\2014\Nsis\dotnetfx4.0.30319.exe" ;添加.NET框架
  152. ; File "F:\Work file\2014\Nsis\dotnetfx35_3.5.30729.1.exe"
  153. ; File "F:\Work file\2014\Nsis\C++RunDll\vcredist_2010_x64.exe"      ;添加C++运行库
  154. ; File "F:\Work file\2014\Nsis\C++RunDll\vcredist_2010_x86.exe"      ;添加C++运行库
  155. ; File "F:\Work file\2014\Nsis\SysData.xml"
  156.   File /r "F:\Work file\2014\智慧校园安装包\WisdomCampus\*.*"


  157.   Push $R0
  158.   IfFileExists C:\Windows\System32\PkgMgr.exe NextStep
  159.   ClearErrors
  160.   ${If} ${RunningX64}
  161.   CopyFiles $INSTDIR\Tools\64bit\PkgMgr.exe C:\Windows\System32                        ;运行IIS安装需要的EXE
  162.   ${Else}
  163.   CopyFiles $INSTDIR\Tools\32bit\PkgMgr.exe C:\Windows\System32
  164.   ${EndIf}
  165.   
  166.   NextStep:
  167. ;检测IIS
  168.   ClearErrors
  169.   ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\InetStp" "MajorVersion"
  170.   ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\InetStp" "MinorVersion"
  171.   IfErrors 0 ExitFunction
  172.   ;没有安装iis
  173.   MessageBox MB_OK  "您当前安装的Microsoft Internet信息服务器版 v$0.$1 版本低于要求版本 v6.0,现在将执行IIS安装,请稍等几分钟。"


  174. ClearErrors
  175.   ${If} ${IsWin2003}
  176.   ${OrIf} ${IsWin2003R2}
  177.   ${OrIf} ${IsWinXP}
  178.   ${OrIf} ${IsWin2000}
  179.   DetailPrint "请在安装程序里执行下一步进行安装"
  180.   ExecWait "$INSTDIR\Tools\IIS\setup.exe /q"
  181. ;对IIS框架进行检验是否安装完成,如若没有,回调IIS安装
  182. ${ElseIf} ${IsWin2008}
  183. DetailPrint "正在安装IIS,请稍等几分钟"
  184. nsExec::Exec '"$INSTDIR\Tools\iis7x_setup.bat" /S'
  185. ${Else}
  186. ${If} ${RunningX64}
  187.   DetailPrint "暂不支持64位下的IIS安装,请安装完IIS后再运行此安装包"
  188. Quit
  189.    ${Else}
  190. DetailPrint "正在安装IIS,请稍等几分钟"
  191.    ExecWait "$INSTDIR\Tools\iis7x_setup.bat" ;WIN7 32下不支持NSEXEC插件
  192.    ${EndIf}
  193.   ${EndIf}
  194.   
  195.   IntCmp $0 6 ExitFunction NextStep ExitFunction
  196.   Goto NextStep



  197.   ExitFunction:
  198.   
  199.   ;Call in.CheckProcess
  200. ;检测C++运行库
  201.   Push $R0
  202.   ClearErrors
  203.   ${If} ${RunningX64}
  204.   ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1D8E6291-B0D5-35EC-8441-6616F567A0F7}" "Version"   ; 检测含有vc的注册表信息是否存在
  205.   IfErrors 0 VSRedistInstalled
  206. ; MessageBox MB_OK  "未安装64位C++运行库"
  207.   Exec "$INSTDIR\Tools\vcredist_2010_x64.exe /q"
  208.   Delete "$INSTDIR\Tools\vcredist_2010_x64.exe"
  209.   ${Else}
  210.   ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{196BB40D-1578-3D01-B289-BEFC77A11A1E}" "Version"   ; 检测含有vc的注册表信息是否存在
  211.   IfErrors 0 VSRedistInstalled
  212. ; MessageBox MB_OK  "未安装86位C++运行库"
  213.   Exec "$INSTDIR\Tools\vcredist_2010_x86.exe /q"
  214.   Delete "$INSTDIR\Tools\vcredist_2010_x86.exe"
  215. ${EndIf}




  216.   VSRedistInstalled:


  217. ;检测是否有.net framework框架
  218.   Call GetNetFrameworkVersion


  219.   Pop $R1
  220.   DetailPrint $R1


  221. ; ${If} $R1 < '3.5.30729'


  222. ; SetDetailsPrint textonly


  223. ; DetailPrint "正在安装 .NET Framework 3.5"


  224. ; SetDetailsPrint listonly


  225. ; SetOutPath "$TEMP"


  226. ; SetOverwrite on


  227. ; File "dotnetfx35_3.5.30729.1.exe"


  228. ; ExecWait '$TEMP\dotnetfx35_3.5.30729.1.exe /q /norestart /ChainingPackage' $R1
  229. ; Delete "$TEMP\dotnetfx35_3.5.30729.1.exe"


  230.   ${If} $R1 < '4.0.30319'
  231.     ${If} ${IsWin2003}
  232.     ${OrIf} ${IsWin2003R2}
  233.     ${OrIf} ${IsWinXP}
  234.     ${OrIf} ${IsWin2000}
  235.       ClearErrors
  236.       ${If} ${RunningX64}
  237.       ExecWait "$INSTDIR\Tools\64bit\wic_x64_chs.exe /q"
  238.       ${Else}
  239.       ExecWait "$INSTDIR\Tools\32bit\wic_x86_chs.exe /q"
  240.       ${EndIf}
  241.     ${EndIf}
  242.   DetailPrint "正在安装 .NET Framework 4.0,可能需要几分钟,请稍等"


  243. ;File "dotnetfx4.0.30319.exe"


  244.   ;ExecWait '$INSTDIR\Tools\dotnetfx4.0.30319.exe  /norestart /ChainingPackage FullX64Bootstrapper' $R1
  245.   ExecWait '$INSTDIR\Tools\dotnetfx4.0.30319.exe /norestart'
  246.   ${EndIf}
  247. ;对.NET框架进行检验是否安装完成,如若没有,回调.NET安装
  248. Call GetNetFrameworkVersion
  249.   Pop $R1
  250.   ${If} $R1 < '4.0.30319'
  251.   DetailPrint ".NET Framework 4.0是必要安装,不能取消此安装,请执行安装"
  252.   Goto VSRedistInstalled
  253.   ${EndIf}
  254.   
  255. ;获取本机IP
  256.   ip::get_ip
  257.   Pop $0
  258.   ; test entry
  259.   ;StrCpy $0 '192.168.0.100;127.0.0.1;152.168.0.101;169.254.0.1;'
  260.   ;Loop:
  261.   Push $0
  262.   Call GetNextIp
  263.   Call CheckIp
  264.   Pop $2 ; Type of current IP-address
  265.   Pop $1 ; Current IP-address
  266.    Pop $0 ; Remaining addresses
  267.   StrCmp $2 '1' '' NoLoopBackIp
  268.   ;  MessageBox MB_OK "LoopBack IP-address: $1"
  269.     Goto Continue
  270.   NoLoopBackIp:
  271.   StrCmp $2 '2' '' NoAPA
  272.   ;  MessageBox MB_OK "Automatic Private IP-address: $1"
  273.     Goto Continue
  274.   NoAPA:
  275.   StrCmp $2 '3' '' NoLanIp
  276.    ; MessageBox MB_OK "Network IP-address: $1"
  277.     StrCpy $local_ip $1
  278. Goto Continue
  279.   NoLanIp:
  280.   ;MessageBox MB_OK "Internet IP-address: $1"
  281.   Continue:
  282.   ;StrCmp $0 '' ExitLoop Loop
  283.   ;ExitLoop:
  284. ;获取IP结束 $local_ip为本机IP


  285. ;获取空闲可用端口
  286.   StrCpy  $ports_firstports 80
  287. ${If} $ports_value != 1
  288. StrCpy  $ports_firstports 8000
  289. ${Endif}
  290.   ${while} $ports_value != 1
  291.   Call check_ports
  292.   ${EndWhile}
  293. ; MessageBox MB_OK $free_ports
  294. ;获取空闲端口结束 空闲端口为$free_ports,$free_ports在check_ports函数里赋值

  295. ;注册MySql服务
  296. ; nsExec::Exec '"$INSTDIR\WebSite\SetWebConfig.exe" /S'
  297.   WriteINIStr "$INSTDIR\Tools\mysql5\my.ini" "WinMySQLAdmin" "Server" "$INSTDIR\Tools\mysql5\bin\mysqld-nt.exe"  ;修改MYSQL INI文件
  298.   WriteINIStr "$INSTDIR\Tools\mysql5\my.ini" "mysqld" "basedir" "$INSTDIR\Tools\mysql5"
  299.   WriteINIStr "$INSTDIR\Tools\mysql5\my.ini" "mysqld" "datadir" "$INSTDIR\Tools\mysql5\data"
  300.   DetailPrint "正在安装Mysql并启动服务"
  301. nsExec::ExecToLog '"$INSTDIR\Tools\mysql5\bin\mysqld-nt.exe" --install mysql --defaults-file="$INSTDIR\Tools\mysql5\my.ini"' ;注册并启动MYSQL服务
  302.   nsExec::ExecToLog 'net start mysql'
  303. ; nsExec::Exec "$INSTDIR\Tools\RegMySql.bat" ;20140807

  304.   
  305. ;如果先安装了.NET框架后安装IIS,就对.NET进行注册
  306.   ;nsExec::ExecToLog 'cmd.exe cd C:\Windows\Microsoft.NET\Framework\v4.0.30319" aspnet_regiis.exe -i'
  307.   nsExec::Exec "$INSTDIR\Tools\RegNet.bat"
  308.   DetailPrint "注册.NET框架"


  309.   ClearErrors
  310. ;生成网站
  311.   StrCpy $1 "v4.0"
  312.   StrCpy $2 "Integrated"
  313.   StrCpy $3 "true"
  314. ;NsisIIs::CreateAppPool "MyWebSiteAppPool"
  315.   NsisIIs::CreateAppPool "KSAppPool"
  316.   Pop $0
  317. ; MessageBox MB_OK $0
  318.   StrCpy $1 "KSAppPool"
  319.   ; StrCpy $1 "DefaultAppPool"
  320.   ClearErrors
  321.   ClearErrors
  322. NsisIIs::CreateWebSite "KSWebSite"  "$INSTDIR\WebSite"  "@$local_ip:$free_ports:"
  323.   Pop $0
  324. ; MessageBox MB_OK $0
  325.   DetailPrint $0
  326.   ${If} $0 == "Create Website Success."
  327.   Push $6
  328.   StrCpy $Index $6


  329. ; InstallUpdateServer:
  330.   ExecWait "$INSTDIR\Tools\setup.exe" ;软件升级的服务的安装
  331. ;  ReadRegDWORD $0 HKLM "SYSTEM\CurrentControlSet\Services\KingsunUpdate" "ImagePath"
  332. StrCpy $update_path $0
  333. ;  StrCpy $empty ""
  334. ;  StrCmp $update_path $empty IsQuit
  335. ;  Goto Finish
  336.   
  337. ;  IsQuit:
  338. ;  MessageBox MB_YESNO|MB_ICONQUESTION|MB_TOPMOST "软件升级服务必须安装的,安装升级服务请点击“是”,如若安装.NET后无法安装升级服务,请点击“否”后中止安装并重启计算机再运行安装包继续余下安装!!" IDNO +2
  339. ;  Goto InstallUpdateServer
  340. ;  Quit
  341.   WriteRegStr HKLM "SOFTWARE\WisdomCampus" "KSWebVersion" "$version_number"
  342.   WriteRegStr HKLM "SOFTWARE\WisdomCampus" "KSWebPath" "$INSTDIR"




  343.   ;写入XML配置文件
  344.   nsisXML::create
  345.   nsisXML::load "$INSTDIR\WebSite\SysData.xml"
  346.   nsisXML::select '/SysData/SysInfo/Version'
  347.   IntCmp $2 0 notFound
  348.   nsisXML::getText
  349.   nsisXML::setText '$version_number'


  350.   nsisXML::select '/SysData/SysInfo/MySQLPath'
  351.   IntCmp $2 0 notFound
  352.   nsisXML::getText
  353.   nsisXML::setText '$INSTDIR\Tools\mysql5'


  354.   nsisXML::select '/SysData/SysInfo/WebsitePath'
  355.   IntCmp $2 0 notFound
  356.   nsisXML::getText
  357.   nsisXML::setText '$INSTDIR\WebSite'


  358.   nsisXML::select '/SysData/SysInfo/ProxyPath'
  359.   IntCmp $2 0 notFound
  360.   nsisXML::getText
  361.   nsisXML::setText "$update_path"


  362.   nsisXML::select '/SysData/SysInfo/WebsiteName'
  363.   IntCmp $2 0 notFound
  364.   nsisXML::getText
  365.   nsisXML::setText "KSWebSite"


  366.   nsisXML::select '/SysData/SysInfo/ServerIP'
  367.   IntCmp $2 0 notFound
  368.   nsisXML::getText
  369.   nsisXML::setText '$local_ip'


  370.   nsisXML::select '/SysData/SysInfo/Website'
  371.   IntCmp $2 0 notFound
  372.   nsisXML::getText
  373.   nsisXML::setText "http://$local_ip:$free_ports/Login.aspx"


  374.   nsisXML::select '/SysData/SysInfo/WebsiteIndexId'
  375.   IntCmp $2 0 notFound
  376.   nsisXML::getText
  377.   nsisXML::setText '$Index'


  378.   nsisXML::save "$INSTDIR\WebSite\SysData.xml"


  379.   ExecWait '$INSTDIR\Tools\AddMime\AddMime.exe'
  380.   Goto Finish
  381.   
  382.   notFound:
  383.   DetailPrint "没有找到系统配置文件"
  384.   
  385.   Finish:
  386.   MessageBox MB_OK "金太阳智慧校园云平台网站安装成功,请在浏览器输入$local_ip:$free_ports/Login.aspx地址访问或在开始菜单栏里的金太阳智慧校园云平台目录下点击WebSite打开网站"
  387.   ;安装成功,写入注册表






  388.   ${ElseIf} $0 == "Error creating website."
  389.   MessageBox MB_OK "安装中止,网站ID错误,请联系管理员"
  390.   Abort
  391.   
  392.   ${ElseIf} $0 == "Error:ADsGetObject Getting IDispatch:iContainer"
  393.     MessageBox MB_OK "IIS没有安装完整,网站生成失败,安装中止!"
  394.   Abort
  395.   
  396.   ${Else}
  397.   MessageBox MB_OK "安装错误并中止,请联系管理员"
  398.   Abort
  399.   ${EndIf}



  400. /* ${Switch} $0
  401.     ${Case} 'Create Website Success'  ;"网站生成成功"
  402.     ;安装完成后拷贝一个配置文件
  403.     CopyFiles $INSTDIR\Tools\IIS\SysData.xml $INSTDIR\Tools\SysData.xml
  404.     MessageBox MB_OK "网站生成成功"
  405. ${Break}


  406.     ${Case} 'Error:ADsGetObject Getting IDispatch:iContainer' ;"安装IIS没有安装完整"
  407.     MessageBox MB_OK "IIS没有安装完整,网站生成失败,安装中止!"
  408.     Abort
  409.     ${Break}
  410. ${EndSwitch}
  411. */






  412. SectionEnd


  413. Section -AdditionalIcons
  414.   ;WriteIniStr "$SMPROGRAMS\方直智慧云平台.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  415.   SetShellVarContext all
  416.   CreateDirectory "$SMPROGRAMS\金太阳智慧校园云平台"
  417.   ;CreateShortCut "$SMPROGRAMS\My application\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  418.   CreateShortCut "$SMPROGRAMS\金太阳智慧校园云平台\Website.lnk" "http://$local_ip:$free_ports/Login.aspx"
  419.   CreateShortCut "$SMPROGRAMS\金太阳智慧校园云平台\Uninstall.lnk" "$INSTDIR\uninst.exe"
  420. SectionEnd


  421. Section -Post
  422.   WriteUninstaller "$INSTDIR\uninst.exe"
  423.   WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  424.   WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  425.   WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  426.   WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  427.   WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
  428. SectionEnd


  429. Function GetNetFrameworkVersion


  430. ;获取.Net Framework版本支持


  431. Push $1


  432. Push $0


  433. ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Install"


  434. ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Version"


  435. StrCmp $0 1 KnowNetFrameworkVersion +1


  436. ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" "Install"


  437. ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" "Version"


  438. StrCmp $0 1 KnowNetFrameworkVersion +1


  439. ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "InstallSuccess"


  440. ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "Version"


  441. StrCmp $0 1 KnowNetFrameworkVersion +1


  442. ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Install"


  443. ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Version"


  444. StrCmp $1 "" +1 +2


  445. StrCpy $1 "2.0.50727.832"


  446. StrCmp $0 1 KnowNetFrameworkVersion +1


  447. ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Install"


  448. ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Version"


  449. StrCmp $1 "" +1 +2


  450. StrCpy $1 "1.1.4322.573"


  451. StrCmp $0 1 KnowNetFrameworkVersion +1


  452. ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0" "Install"


  453. ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0" "Version"


  454. StrCmp $1 "" +1 +2


  455. StrCpy $1 "1.0.3705.0"


  456. StrCmp $0 1 KnowNetFrameworkVersion +1


  457. StrCpy $1 "not .NetFramework"


  458. KnowNetFrameworkVersion:


  459. Pop $0


  460. Exch $1


  461. FunctionEnd

  462. ; Function GetNextIp
  463. ; input: head of stack
  464. ; format: 'ip1;ip2;ip3;ip4;'
  465. ; output: 'ip1' head of stack
  466. ;         'ip2;ip3;ip4;' second entry of stack


  467. Function GetNextIp
  468.   Exch $0
  469.   Push $1
  470.   Push $2
  471.   Strcpy $2 0             ; Counter
  472.   Loop:
  473.     IntOp $2 $2 + 1
  474.     StrCpy $1 $0 1 $2
  475.     StrCmp $1 '' ExitLoop
  476.     StrCmp $1 ';' '' Loop
  477.     StrCpy $1 $0 $2       ; IP-address
  478.     IntOp $2 $2 + 1
  479.     StrCpy $0 $0 '' $2    ; Remaining string
  480.   ExitLoop:
  481.   Pop $2
  482.   Push $0
  483.   Exch 2
  484.   Pop $0
  485.   Exch $1
  486. FunctionEnd


  487. ; Function CheckIP
  488. ; input: IP-address on stack
  489. ; output: additional entry on stack
  490. ;         1 - LoopBack IP (localhost, indicates no connection to a LAN or to the internet).
  491. ;         2 - Automatic Private IP Address (no DHCP server).
  492. ;         3 - Network IP.
  493. ;         4 - Internet IP.
  494. ; Eg:
  495. ; Push '192.168.0.100'
  496. ; Call CheckIP
  497. ; Pop $0 ; Contains '3'
  498. ; Pop $1 ; Contains '192.168.0.100'


  499. Function CheckIP
  500.   Exch $0
  501.   Push $1


  502.   ; Check 127.x.x.x
  503.   Push '127.0.0.0'
  504.   Push $0
  505.   Call VersionCheck
  506.   Pop $1
  507.   StrCmp $1 2 '' Range1     ; IP cannot be in range of LoopBack addresses
  508.   Push '127.255.255.255'
  509.   Push $0
  510.   Call VersionCheck
  511.   Pop $1
  512.   StrCmp $1 1 LoopBack      ; We found a LoopBack IP


  513.   ; Check 10.x.x.x
  514.   Range1:
  515.   Push '10.0.0.0'
  516.   Push $0
  517.   Call VersionCheck
  518.   Pop $1
  519.   StrCmp $1 2 '' Range2     ; IP cannot be in range 1
  520.   Push '10.255.255.255'
  521.   Push $0
  522.   Call VersionCheck
  523.   Pop $1
  524.   StrCmp $1 1 LanIp         ; We found a LanIp


  525.   ; Check 172.16.x.x to 172.31.x.x
  526.   Range2:
  527.   Push '172.16.0.0'
  528.   Push $0
  529.   Call VersionCheck
  530.   Pop $1
  531.   StrCmp $1 2 '' Range3     ; IP cannot be in range 2
  532.   Push '172.31.255.255'
  533.   Push $0
  534.   Call VersionCheck
  535.   Pop $1
  536.   StrCmp $1 1 LanIp         ; We found a LanIp


  537.   ; Check 192.168.x.x
  538.   Range3:
  539.   Push '192.168.0.0'
  540.   Push $0
  541.   Call VersionCheck
  542.   Pop $1
  543.   StrCmp $1 2 '' Range4     ; IP cannot be in range 3
  544.   Push '192.168.255.255'
  545.   Push $0
  546.   Call VersionCheck
  547.   Pop $1
  548.   StrCmp $1 1 LanIp         ; We found a LanIp


  549.   ; Check 169.254.x.x
  550.   Range4:
  551.   Push '169.254.0.0'
  552.   Push $0
  553.   Call VersionCheck
  554.   Pop $1
  555.   StrCmp $1 2 '' InternetIp ; It should be an internet IP
  556.   Push '169.254.255.255'
  557.   Push $0
  558.   Call VersionCheck
  559.   Pop $1
  560.   StrCmp $1 1 APA           ; We found an Automatic Private IP Address


  561.   Goto InternetIp           ; Remaining addresses are internet IPs


  562.   LoopBack:
  563.   StrCpy $1 1
  564.   Goto Exit


  565.   APA:
  566.   StrCpy $1 2
  567.   Goto Exit


  568.   LanIp:
  569.   StrCpy $1 3
  570.   Goto Exit


  571.   InternetIp:
  572.   StrCpy $1 4


  573.   Exit:
  574.   Exch $1
  575.   Exch 1
  576.   Exch $0
  577.   Exch 1
  578. FunctionEnd


  579. ; Function VersionCheck
  580. ; input: 'v1', 'v2' on stack
  581. ; output 1 - if number 1 is newer
  582. ;        2 - if number 2 is newer
  583. ;        0 - if it is the same verion
  584. ; Eg:
  585. ; Push '3.5.1.4'
  586. ; Push '3.5'
  587. ; Call VersionCheck
  588. ; Pop $0 ; now contains 1


  589. Function VersionCheck
  590.   Exch $0 ;second versionnumber
  591.   Exch
  592.   Exch $1 ;first versionnumber
  593.   Push $R0 ;counter for $0
  594.   Push $R1 ;counter for $1
  595.   Push $3 ;temp char
  596.   Push $4 ;temp string for $0
  597.   Push $5 ;temp string for $1
  598.   StrCpy $R0 "-1"
  599.   StrCpy $R1 "-1"
  600.   Start:
  601.   StrCpy $4 ""
  602.   DotLoop0:
  603.   IntOp $R0 $R0 + 1
  604.   StrCpy $3 $0 1 $R0
  605.   StrCmp $3 "" DotFound0
  606.   StrCmp $3 "." DotFound0
  607.   StrCpy $4 $4$3
  608.   Goto DotLoop0
  609.   DotFound0:
  610.   StrCpy $5 ""
  611.   DotLoop1:
  612.   IntOp $R1 $R1 + 1
  613.   StrCpy $3 $1 1 $R1
  614.   StrCmp $3 "" DotFound1
  615.   StrCmp $3 "." DotFound1
  616.   StrCpy $5 $5$3
  617.   Goto DotLoop1
  618.   DotFound1:
  619.   Strcmp $4 "" 0 Not4
  620.     StrCmp $5 "" Equal
  621.     Goto Ver2Less
  622.   Not4:
  623.   StrCmp $5 "" Ver2More
  624.   IntCmp $4 $5 Start Ver2Less Ver2More
  625.   Equal:
  626.   StrCpy $0 "0"
  627.   Goto Finish
  628.   Ver2Less:
  629.   StrCpy $0 "1"
  630.   Goto Finish
  631.   Ver2More:
  632.   StrCpy $0 "2"
  633.   Finish:
  634.   Pop $5
  635.   Pop $4
  636.   Pop $3
  637.   Pop $R1
  638.   Pop $R0
  639.   Pop $1
  640.   Exch $0
  641. FunctionEnd


  642. Function check_ports
  643. StrCpy $1 $ports_firstports
  644. ;validate_port:
  645.   TCP::CheckPort $1
  646.   Pop $0
  647. ;DetailPrint $0
  648. ${Switch} $0
  649.     ${Case} 'free'  ;"端口空闲."
  650.     StrCpy $ports_value 1
  651. ${Break}


  652.     ${Case} 'socket_error' ;"非法 TCP 端口号. 端口号必须在 1 至 65535 之间."
  653.     StrCpy $ports_value 0
  654.     IntOp $ports_firstports $ports_firstports + 1
  655.     ${Break}


  656.     ${Case} 'inuse' ; "端口正在被程序使用."
  657.     StrCpy $ports_value 2
  658.     IntOp $ports_firstports $ports_firstports + 1
  659.     ${Break}


  660.     ${Case} 'bind_error' ;"端口绑定"
  661.     StrCpy $ports_value 3
  662.     IntOp $ports_firstports $ports_firstports + 1
  663.     ${Break}


  664. ${EndSwitch}
  665.     StrCpy $free_ports $1


  666. FunctionEnd


  667. ;Function in.CheckProcess
  668. ;DetectProc:
  669. ;;FindProcDLL::FindProc ${PRODUCT_PROC_NAME}


  670.    ;; StrCmp $R0 1 +3 +9


  671. ;FindProcDLL::FindProc ${PRODUCT_PROC_NAME}


  672.     ;StrCmp $R0 1 +1 +7
  673.    ; MessageBox MB_OKCANCEL|MB_ICONSTOP "安装程序检测到 ${PRODUCT_NAME} 正在运行。$\r$\n$\r$\n点击 “确定” 强制关闭${PRODUCT_NAME},继续安装。$\r$\n点击 “取消” 退出安装程序。" IDCANCEL Exit
  674.     ;Retry:
  675. ; DetailPrint "正在退出$(^Name),请稍候..."


  676. ;KillProcDLL::KillProc ${PRODUCT_PROC_NAME}
  677.     ; sleep 444
  678.    ;  goto DetectProc
  679.    ;  Exit:
  680.    ;  ;Abort
  681.    ;  Quit
  682. ;FunctionEnd




  683. Function LaunchLink
  684. ExecShell "open" "http://$local_ip:$free_ports/Login.aspx"
  685. ; IEFunctions::OpenBrowser /NOUNLOAD
  686. ; IEFunctions::SurfTo /NOUNLOAD "http://192.168.3.92:8003/default.aspx"
  687. FunctionEnd
  688. /******************************
  689. *  以下是安装程序的卸载部分  *
  690. ******************************/


  691. Section Uninstall
  692.   ;ExecWait "$PROGRAMFILES\WisdomCampus\Tools\DelMySql.bat"
  693.   isfound:
  694.   nsExec::Exec 'NET STOP "KingsunUpdate"'
  695.   MessageBox MB_OK "请选择删除KingsunSoftUpdateSetup,然后点击完成"
  696.   ExecWait "$INSTDIR\Tools\setup.exe" ;软件升级的服务的的删除
  697.   ReadRegDWORD $0 HKLM "SYSTEM\CurrentControlSet\Services\KingsunUpdate" "ImagePath"
  698.   StrCpy $empty ""
  699.   StrCmp $0 $empty nofound
  700.   goto isfound
  701.   
  702.   nofound:
  703. ;  nsExec::ExecToLog 'net stop mysql' ;停止并删除MYSQL服务
  704. ;  nsExec::ExecToLog '"$INSTDIR\Tools\mysql5\bin\mysqld-nt.exe" --remove mysql --defaults-file="$INSTDIR\Tools\mysql5\my.ini"'
  705.   nsExec::Exec "$INSTDIR\Tools\DelMySql.bat"
  706. ; UninstallUpdateServer:
  707. ;  ExecWait "$INSTDIR\Tools\setup.exe" ;软件升级的服务的的删除
  708. ;  ReadRegDWORD $0 HKLM "SYSTEM\ControlSet001\Services\Services" "ImagePath"
  709. ;  StrCpy $empty ""
  710. ;  StrCmp $0 $empty UninstallUpdateServer
  711.   
  712.   DeleteRegKey /ifempty HKLM "Software\WisdomCampus"
  713.   Delete "$INSTDIR\${PRODUCT_NAME}.url"
  714.   strCpy $XML_PATH '$INSTDIR\WebSite\SysData.xml'
  715.   nsisXML::create ;根据Index删除网站,Index值为$3
  716.   nsisXML::load "$XML_PATH"
  717.   nsisXML::select '/SysData/SysInfo/WebsiteIndexId'
  718.   IntCmp $2 0 notFound
  719.   nsisXML::getText
  720.   Push $3
  721.   StrCmp $3 "" notFound
  722.   NsisIIs::DeleteWebSite "$3"


  723. notFound:
  724. RMDir /r "$INSTDIR\Tools\*.*"
  725.   RMDir /r "$INSTDIR\WebSite\*.*"


  726. SetShellVarContext all
  727.   Delete "$SMPROGRAMS\金太阳智慧校园云平台\Uninstall.lnk"
  728.   Delete "$SMPROGRAMS\金太阳智慧校园云平台\Website.lnk"
  729.   RMDir /r "$SMPROGRAMS\金太阳智慧校园云平台"
  730.   Delete "$INSTDIR\uninst.exe"
  731.   


  732.   NsisIIs::DeleteAppPool "KSAppPool"    ;删除程序池
  733.   DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  734.   SetAutoClose true
  735. SectionEnd


  736. #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#


  737. Function un.onInit
  738.   FindProcDLL::FindProc "${PRODUCT_PROC_NAME}.exe"
  739.    Pop $R0
  740.    IntCmp $R0 1 0 no_run
  741.    MessageBox MB_ICONSTOP "安装程序检测到 ${PRODUCT_PROC_NAME} 正在运行,请退出程序后重试"
  742.    Quit
  743.    no_run:
  744.   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 $(^Name) ,及其所有的组件?" IDYES +2
  745.   Abort
  746. FunctionEnd


  747. Function un.onUninstSuccess
  748.   HideWindow
  749.   MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
  750. FunctionEnd
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-17 22:15 , Processed in 0.110687 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表