判断mysql是否安装脚本

; 该脚本使用 HM VNISEdit 脚本编辑器向导产生
 ; 安装程序初始定义常量
 !define PRODUCT_NAME "XX广告制作软件"
 !define PRODUCT_VERSION "2.2"
 !define PRODUCT_PUBLISHER "XX.com, Inc."
 !define PRODUCT_WEB_SITE "http://www.1bsoft.com"
 !define PRODUCT_DIR_REGKEY "SoftwareMicrosoftWindowsCurrentVersionApp PathsYBest.Ads.exe"
 !define PRODUCT_UNINST_KEY "SoftwareMicrosoftWindowsCurrentVersionUninstall${PRODUCT_NAME}"
 !define PRODUCT_UNINST_ROOT_KEY "HKLM"
 SetCompressor lzma
 ; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
 !include "MUI.nsh"
 !include "WordFunc.nsh"
 ; MUI 预定义常量
 !define MUI_ABORTWARNING
 !define MUI_ICON "ybkj.ico"
 !define MUI_UNICON "${NSISDIR}ContribGraphicsIconsmodern-uninstall.ico"
 ; 欢迎页面
 !insertmacro MUI_PAGE_WELCOME
 ; 许可协议页面
 !insertmacro MUI_PAGE_LICENSE "Readme.txt"
 ; 安装目录选择页面
 !insertmacro MUI_PAGE_DIRECTORY
 ; 安装过程页面
 !insertmacro MUI_PAGE_INSTFILES
 ; 安装完成页面
 !define MUI_FINISHPAGE_RUN "$INSTDIRYBest.Ads.exe"
 !insertmacro MUI_PAGE_FINISH
 ; 安装卸载过程页面
 !insertmacro MUI_UNPAGE_INSTFILES
 ; 安装界面包含的语言设置
 !insertmacro MUI_LANGUAGE "SimpChinese"
 ;文件版本声明
 VIProductVersion "2.2.0.0"
 VIAddVersionKey /LANG=2052 "ProductName" "XX广告制作软件"
 VIAddVersionKey /LANG=2052 "Comments" "软件版权归XX软件所有,他人不得复制或二次开发本程序。"
 VIAddVersionKey /LANG=2052 "CompanyName" "www.XX.com"
 VIAddVersionKey /LANG=2052 "LegalTrademarks" "XX软件"
 VIAddVersionKey /LANG=2052 "LegalCopyright" "XX.com"
 VIAddVersionKey /LANG=2052 "FileDescription" "XX广告制作软件安装程序"
 VIAddVersionKey /LANG=2052 "FileVersion" "2.2.0.0"
 ; 安装预释放文件
 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
 ; ------ MUI 现代界面定义结束 ------
 Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
 OutFile "YBSetup.exe"
 InstallDir "$PROGRAMFILESXX广告制作软件"
 InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
 ShowInstDetails show
 ShowUnInstDetails show
 BrandingText "XX软件 www.XX.com"
 DirText "安装向导将把 $(^NameDA) 安装在下列文件夹,如果要安装到其他文件夹请单击 [浏览(B)] 进行选择。"
 Section "MainSection" SEC01
 SetOutPath "$INSTDIR"
 SetOverwrite ifnewer
 CreateDirectory "$SMPROGRAMSXX广告制作软件"
 CreateShortCut "$SMPROGRAMSXX广告制作软件XX广告制作软件.lnk" "$INSTDIRYBest.Ads.exe"
 CreateShortCut "$DESKTOPXX广告制作软件.lnk" "$INSTDIRYBest.Ads.exe"
 File "DevComponents.DotNetBar2.dll"
 File "DevComponents.DotNetBar2.xml"
 File "LitJSON.dll"
 File "MySql.Data.dll"
 File "NPOI.dll"
 File "ybkj.ico"
 File "YBest.Ads.exe"
 File "YBest.Ads.exe.config"
 File "YBest.BLL.dll"
 File "YBest.Common.dll"
 File "YBest.DAL.dll"
 File "YBest.DBUtility.dll"
 File "YBest.Model.dll"
 File "Readme.txt"
 File "MqttLib.dll"
 File "PullService.dll"
 SetOutPath "$INSTDIRXmlConfig"
 SetOverwrite ifnewer
 File /r "XmlConfig*"
 SetOutPath "$INSTDIRimages"
 SetOverwrite ifnewer
 File /r "images*"
 SetOutPath "$INSTDIRmysql5.1"
 SetOverwrite ifnewer
 File /r "mysql5.1*"
 ;安装mysql服务
 call installMysql
 SectionEnd
 Section -AdditionalIcons
 WriteIniStr "$INSTDIR${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
 CreateShortCut "$SMPROGRAMSXX广告制作软件XX软件官网.lnk" "$INSTDIR${PRODUCT_NAME}.url"
 CreateShortCut "$SMPROGRAMSXX广告制作软件卸载${PRODUCT_NAME}.lnk" "$INSTDIRuninst.exe"
 SectionEnd
 Section -Post
 WriteUninstaller "$INSTDIRuninst.exe"
 WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIRAdsBow.exe"
 WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
 WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIRuninst.exe"
 WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIRAdsBow.exe"
 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}"
 WriteRegDword HKLM "${PRODUCT_DIR_REGKEY}" "Installed" 1
 WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "InstalledPath" "$INSTDIR"
 WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "version" "${PRODUCT_VERSION}" ;写入版本号
 SectionEnd
 Section -.NET
 Call GetNetFrameworkVersion
 Pop $R1
 ${If} $R1 < '2.0.50727'
 SetDetailsPrint textonly
 DetailPrint "正在安装 .NET Framework 2.0,这个可能需要几分钟,请耐心等待..."
 SetDetailsPrint listonly
 SetOutPath "$TEMP"
 SetOverwrite on
 File "NetFx20SP2_x86.exe"
 ExecWait '$TEMPNetFx20SP2_x86.exe /quiet /norestart' $R1
 Delete "$TEMPNetFx20SP2_x86.exe"
 ${EndIf}
 SectionEnd
 /******************************
 * 以下是安装程序的卸载部分 *
 ******************************/
 Section Uninstall
 Delete "$INSTDIR${PRODUCT_NAME}.url"
 Delete "$INSTDIRuninst.exe"
 Delete "$INSTDIRYBest.Ads.exe"
 Delete "$INSTDIRYBest.Ads.exe.config"
 Delete "$INSTDIRYBest.BLL.dll"
 Delete "$INSTDIRYBest.Common.dll"
 Delete "$INSTDIRYBest.DAL.dll"
 Delete "$INSTDIRYBest.DBUtility.dll"
 Delete "$INSTDIRYBest.Model.dll"
 Delete "$INSTDIRDevComponents.DotNetBar2.dll"
 Delete "$INSTDIRDevComponents.DotNetBar2.xml"
 Delete "$INSTDIRLitJSON.dll"
 Delete "$INSTDIRMySql.Data.dll"
 Delete "$INSTDIRNPOI.dll"
 Delete "$INSTDIRybkj.ico"
 Delete "$INSTDIRReadme.txt"
 Delete "$INSTDIRMqttLib.dll"
 Delete "$INSTDIRPullService.dll"
 ;停止mysql服务 并移除服务
 call un.removeService
 ; 循环删除文件直至删除文件夹
 RMDir /r "$INSTDIRimages"
 RMDir /r "$INSTDIRXmlConfig"
 RMDir /r "$INSTDIRmysql5.1"
 Delete "$SMPROGRAMSXX广告制作软件卸载${PRODUCT_NAME}.lnk"
 Delete "$SMPROGRAMSXX广告制作软件XX软件官网.lnk"
 Delete "$DESKTOPXX广告制作软件.lnk"
 Delete "$SMPROGRAMSXX广告制作软件XX广告制作软件.lnk"
 RMDir "$SMPROGRAMSXX广告制作软件"
 RMDir "$INSTDIR"
 DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
 DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
 SetAutoClose true
 SectionEnd
 #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
 Function GetNetFrameworkVersion
 ;获取.Net Framework版本,支持
 Push $1
 Push $0
 ReadRegDWORD $0 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv3.5" "Install"
 ReadRegDWORD $1 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv3.5" "Version"
 StrCmp $0 1 KnowNetFrameworkVersion +1
 ReadRegDWORD $0 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv3.0Setup" "InstallSuccess"
 ReadRegDWORD $1 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv3.0Setup" "Version"
 StrCmp $0 1 KnowNetFrameworkVersion +1
 ReadRegDWORD $0 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv2.0.50727" "Install"
 ReadRegDWORD $1 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv2.0.50727" "Version"
 StrCmp $1 "" +1 +2
 StrCpy $1 "2.0.50727.832"
 StrCmp $0 1 KnowNetFrameworkVersion +1
 ReadRegDWORD $0 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv1.1.4322" "Install"
 ReadRegDWORD $1 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv1.1.4322" "Version"
 StrCmp $1 "" +1 +2
 StrCpy $1 "1.1.4322.573"
 StrCmp $0 1 KnowNetFrameworkVersion +1
 ReadRegDWORD $0 HKLM "SOFTWAREMicrosoft.NETFrameworkpolicyv1.0" "Install"
 ReadRegDWORD $1 HKLM "SOFTWAREMicrosoft.NETFrameworkpolicyv1.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
 ;安装mysql服务
 Function installMysql
 Push "mysqld.exe"
 ProcessWork::existsprocess
 Pop $R0
 IntCmp $R0 0 no_install ;判断mysql是否已经安装
 ;写入注册表表示不是本程序安装的mysql,卸载的时候不需要卸载mysql数据库
 WriteRegDword HKLM "${PRODUCT_DIR_REGKEY}" "MySqlInstalled" 0
 MessageBox MB_OK|MB_ICONEXCLAMATION "本机已安装了mysql数据库,请手动导入数据信息,谢谢!"
 Goto done ;退出安装mysql
 no_install: ;没有安装则安装
 ExecWait "$INSTDIRmysql5.1binmysqld --install mysql"
 ;设置mysql的环境变量到PATH路径
 ReadRegStr $0 HKLM "SYSTEMCurrentControlSetControlSession ManagerEnvironment" "Path"
 WriteRegExpandStr HKLM "SYSTEMCurrentControlSetControlSession ManagerEnvironment" "Path" "$0;$INSTDIRmysql5.1bin"
 ;刷新环境变量
 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment"
 ;启动服务
 ExecWait "net start mysql"
 ;写入注册表表示是本程序安装的mysql,方便卸载的时候卸载mysql数据库
 WriteRegDword HKLM "${PRODUCT_DIR_REGKEY}" "MySqlInstalled" 1
 ;完成
 done:
 FunctionEnd
 Function .onInit
 InitPluginsDir
 ;创建互斥防止重复运行
 System::Call 'kernel32::CreateMutexA(i 0, i 0, t "YBSetup") i .r1 ?e'
 Pop $R0
 StrCmp $R0 0 +3
 MessageBox MB_OK|MB_ICONEXCLAMATION "有一个YBSetup安装向导已经运行!"
 Abort
 ;禁止多次安装实例 start
 ReadRegDWORD $0 HKLM '${PRODUCT_DIR_REGKEY}' "Installed"
 IntCmp $0 +1 +4
 MessageBox MB_OK|MB_USERICON '$(^Name) 已安装在计算机中。如需重新安装,请卸载已有的安装。'
 Quit
 nop
 ;禁止多次安装实例 end
 FunctionEnd
 ;--------------- 移除mysql服务 ----------------
 Function un.removeService
 ;读取是否是本程序安装mysql
 ReadRegDWORD $0 HKLM '${PRODUCT_DIR_REGKEY}' "MySqlInstalled"
 IntCmp $0 1 0 clearDb
 ;停止mysql服务
 ExecWait "net stop Mysql"
 ;移除mysql服务
 ExecWait "$INSTDIRmysql5.1binmysqld --remove Mysql"
 ;移除环境变量
 ReadRegStr $R0 HKLM "SYSTEMCurrentControlSetControlSession ManagerEnvironment" "Path"
 ${WordReplace} $R0 ";$INSTDIRmysql5.1bin" "" "+" $R1
 ;MessageBox MB_OK|MB_USERICON '$R0 - $INSTDIR - $R1 '
 WriteRegExpandStr HKLM "SYSTEMCurrentControlSetControlSession ManagerEnvironment" "Path" "$R1"
 ;清除数据库信息
 clearDb:
 FunctionEnd
 ;---------------------------------
 Function un.onInit
 FindProcDLL::FindProc "YBest.Ads.exe"
 Pop $R0
 IntCmp $R0 1 0 no_run
 MessageBox MB_ICONSTOP "安装程序检测到 $(^Name) 正在运行,请退出程序后重试"
 Quit
 no_run:
 MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 $(^Name) ,及其所有的组件?" IDYES +2
 Abort
 FunctionEnd
 Function un.onUninstSuccess
 HideWindow
 MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
 FunctionEnd
 nsis更新升级mysql完整实例代码

; 安装程序初始定义常量
 !define PRODUCT_NAME "XX广告制作管理软件"
 !define PRODUCT_VERSION "2.2"
 !define PRODUCT_DIR_REGKEY "SoftwareMicrosoftWindowsCurrentVersionApp PathsYBest.Ads.exe"
 SetCompressor lzma
 ; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
 !include "MUI.nsh"
 !include "WordFunc.nsh"
 ; MUI 预定义常量
 !define MUI_ICON "ybkj.ico"
 ; 欢迎页面
 !insertmacro MUI_PAGE_WELCOME
 ; 许可协议页面
 !insertmacro MUI_PAGE_LICENSE "Readme.txt"
 ; 安装过程页面
 !insertmacro MUI_PAGE_INSTFILES
 ; 安装界面包含的语言设置
 !insertmacro MUI_LANGUAGE "SimpChinese"
 ;文件版本声明
 VIProductVersion "2.2.0.0"
 VIAddVersionKey /LANG=2052 "ProductName" "${PRODUCT_NAME}"
 VIAddVersionKey /LANG=2052 "Comments" "软件版权归XX软件所有,他人不得复制或二次开发本程序。"
 VIAddVersionKey /LANG=2052 "CompanyName" "www.XX.com"
 VIAddVersionKey /LANG=2052 "LegalTrademarks" "XX软件"
 VIAddVersionKey /LANG=2052 "LegalCopyright" "XX.com"
 VIAddVersionKey /LANG=2052 "FileDescription" "XX广告制作软件-V${PRODUCT_VERSION}升级程序"
 VIAddVersionKey /LANG=2052 "FileVersion" "${PRODUCT_VERSION}"
 ; 安装预释放文件
 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
 ; ------ MUI 现代界面定义结束 ------
 Name "${PRODUCT_NAME} - V${PRODUCT_VERSION}升级程序"
 OutFile "${PRODUCT_NAME}-V${PRODUCT_VERSION}升级包.exe"
 InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
 ShowInstDetails hide
 BrandingText "XX软件 www.XX.com"
 ; ------ 更新软件 ------
 Section "UpdateSoft" SEC01
 ;休眠1秒钟 展示安装效果
 Sleep 1000
 SetDetailsPrint textonly
 DetailPrint "正在升级 ${PRODUCT_NAME},请单击[关闭]按钮完成升级!"
 SetDetailsPrint listonly
 SectionIn RO
 SetOutPath "$INSTDIR"
 ;更新比原目录日期新的文件
 SetOverwrite ifnewer
 ;升级文件
 File "YBest.Ads.exe"
 File "YBest.Ads.exe.config"
 File "YBest.BLL.dll"
 File "YBest.Common.dll"
 File "YBest.DAL.dll"
 File "YBest.DBUtility.dll"
 File "YBest.Model.dll"
 File "MqttLib.dll"
 File "PullService.dll"
 File "更新说明.txt"
 File "update.sql"
 ;更新数据库
 Call updateDB
 WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "version" "${PRODUCT_VERSION}" ;写入版本号
 ;指定以记事本打开说明
 ;Exec '"$SYSDIRnotepad.exe" "$INSTDIR更新说明.txt"'
 SectionEnd
 ; ------ 更新软件结束 ------
 ;更新数据库
 Function updateDB
 ;检查mysql服务是否启动
 Push "mysqld.exe"
 ProcessWork::existsprocess
 Pop $R0
 IntCmp $R0 1 ExecSql
 MessageBox MB_OK|MB_ICONEXCLAMATION "mysql数据库服务未启动,请启动后再升级程序!"
 Quit ;未启动则 退出更新安装程序
 ExecSql:
 ;更新数据
 ExecWait 'mysql --user=root --password=123456 --execute="source $INSTDIRupdate.sql"' $2
 StrCmp $2 1 0 endinst
 MessageBox MB_OK|MB_ICONEXCLAMATION "数据库更新失败!请确认账号密码是否正确或数据库已安装!"
 Delete "$INSTDIRupdate.sql" ;删除文件
 Quit ;未启动则 退出更新安装程序
 endinst:
 Delete "$INSTDIRupdate.sql" ;删除文件
 FunctionEnd
 Function .onInit
 ;判断是否已安装
 ReadRegStr $0 HKLM "${PRODUCT_DIR_REGKEY}" ""
 StrCmp $0 "" 0 NoAbort
 MessageBox MB_OK|MB_ICONEXCLAMATION "您未正确安装${PRODUCT_NAME},不能使用此升级程序!"
 Abort ;退出安装程序
 NoAbort:
 ;程序正在运行则关闭程序
 Push $R0
 CheckProc:
 Push "YBest.Ads.exe"
 ProcessWork::existsprocess
 Pop $R0
 IntCmp $R0 0 Done
 MessageBox MB_OKCANCEL|MB_ICONSTOP "升级程序检测到 ${PRODUCT_NAME} 正在运行。$r$n$r$n点击 “确定” 强制关闭${PRODUCT_NAME},继续升级。$r$n点击 “取消” 退出安装程序。" IDCANCEL Exit
 Push "YBest.Ads.exe"
 Processwork::KillProcess
 Sleep 1000
 Goto CheckProc
 Exit:
 Abort
 Done:
 Pop $R0
 FunctionEnd
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容