Чтобы добавить возможность деинсталляции MySQL сервера при деинсталляции основной программы, нужно в код InnoSetup добавить следующую инструкцию
1 2 |
[UninstallRun] Filename: msiexec; Parameters: "/i ""{app}\mysql-5.5.23-winx64.msi "" " |
Код целиком, будет выглядеть следующим образом, он включает в себя инсталляцию основной программы, инсталляцию сервера базы данных и его конфигурирование, и его деинсталляцию при деинсталляции основной программы.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
; Script generated by the Inno Setup Script Wizard. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "MySQL_Install" #define MyAppVersion "1.5" #define MyAppPublisher "My Company, Inc." #define MyAppURL "http://www.example.com/" #define MyAppExeName "MySQL_TestInstall.exe" [Setup] ; NOTE: The value of AppId uniquely identifies this application. ; Do not use the same AppId value in installers for other applications. ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) AppId={{73F53ED9-3A82-4F4D-8E0C-19BDDE5AD3E6} AppName={#MyAppName} AppVersion={#MyAppVersion} ;AppVerName={#MyAppName} {#MyAppVersion} AppPublisher={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} DefaultDirName={pf}\{#MyAppName} DisableProgramGroupPage=yes OutputDir=C:\Users\NoName\Desktop\ComplierOutput OutputBaseFilename=MySQL_TestSetup Compression=lzma SolidCompression=yes [Languages] Name: "english"; MessagesFile: "compiler:Default.isl" [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1 [Files] ;Source: "C:\Program Files (x86)\Inno Setup 5\Examples\MySQL_TestInstall.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "C:\Users\NoName\Desktop\MySQL_InstallTest_SourceFiles\InnoSetup_Test.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "C:\Users\NoName\Desktop\MySQL_InstallTest_SourceFiles\mysql-5.5.23-winx64.msi"; DestDir: "{app}"; Flags: ignoreversion Source: "C:\Users\NoName\Desktop\MySQL_InstallTest_SourceFiles\test_dump.sql"; DestDir: "{app}"; Flags: ignoreversion ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons] Name: "{commonprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon [Run] ;Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent ;------------------------------------------------------INSTALLING Filename: msiexec; Parameters: "/i ""{app}\mysql-5.5.23-winx64.msi "" /qn INSTALLDIR=""C:\mysql"" DATADIR=""C:\mysql\data"" "; WorkingDir:{app}; StatusMsg: Please wait while we install mysql-5.5.23-winx64.msi; Flags: runhidden ;Filename: msiexec; Parameters: "/i mysql-5.5.23-winx64.msi /qn INSTALLDIR=""C:\mysql"" DATADIR=""C:\mysql\data"" "; WorkingDir:{app}; StatusMsg: Please wait while we install mysql-5.5.23-winx64.msi; Flags: runhidden Filename: C:\mysql\bin\mysqld.exe; Parameters:" --install"; WorkingDir: {app}; StatusMsg: Installing MySQL services; Description: Installing MySQL Service; Flags: runhidden ;-------------------------------------------------------CONFIGURING Filename: C:\mysql\bin\MySQLInstanceConfig.exe; Parameters:"-i -q ""-lC:\mysql\mysql_install_log.txt"" ""-nMySQL Server 5.5"" ""-pC:\mysql"" -v5.5.23 ""-tC:\mysql\my-template.ini"" ""-cC:\mysql\my2.ini"" ServerType=SERVER DatabaseType=MIXED Port=3306 StrictMode=yes ConnectionCount=15 Charset=utf8 ServiceName=MYSQL AddBinToPath=yes RootPassword=masterkey"; WorkingDir: {app}; StatusMsg: Configuring MySQL services; Description: Configuring MySQL Service; Flags: runhidden ; Here we starting mysql service Filename: net.exe; Parameters: start mysql; StatusMsg: Starting MySQL server; Description: Starting MySQL Server; Flags: runhidden ;-------------------------------------------- Setting new password for root user Filename: C:\mysql\bin\mysqladmin.exe; Parameters: "-u root password ""masterkey"" "; WorkingDir: {app}; StatusMsg: Setting new password; Flags: runhidden ;Filename: C:\mysql\bin\mysql.exe; Parameters: "-e ""update mysql.user set password=PASSWORD('masterkey') where user='root';"" -u root"; WorkingDir: {app}; StatusMsg: Configuring MYSQL ; Flags: runhidden ;Filename: C:\mysql\bin\mysql.exe; Parameters: "-e ""flush privileges;"" -u root -pmasterkey"; WorkingDir: {app}; StatusMsg: Configuring Database Servers; Flags: runhidden ;Filename: C:\mysql\bin\mysql.exe; Parameters: "-u root -pmasterkey -h localhost --execute=""SOURCE database.sql"""; WorkingDir: {app}; StatusMsg: Loading Database; Flags: runhidden ;------------------------------------------------- Creating Empty Database and loadind dump Filename: C:\mysql\bin\mysql.exe; Parameters: "-u root -pmasterkey -e ""create database test_db;"" "; WorkingDir: {app}; StatusMsg: Loading Database; Flags: runhidden ; Loading dump Filename: C:\mysql\bin\mysql.exe; Parameters: "-u root -pmasterkey test_db < {app}\test_dump.sql; "; WorkingDir: {app}; StatusMsg: Loading Database; Flags: runhidden ;------------------------------------------------- Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent ;---------------------------------------------Additional Uninstall [UninstallRun] Filename: msiexec; Parameters: "/i ""{app}\mysql-5.5.23-winx64.msi "" " [Code] function MySQL_Is(): Boolean; var iResultCode: Integer; begin Result := true; if (not RegKeyExists(HKLM, 'SOFTWARE\MySQL AB\MySQL Server 5.5')) or (not FileExists(ExpandConstant('{reg:HKLM\SOFTWARE\MySQL AB\MySQL Server 5.5,Location}\bin\mysql.exe'))) then begin ExtractTemporaryFile('mysql-5.5.23-winx64.msi'); Exec('msiexec.exe', '/i mysql-5.5.23-winx64.msi /qn INSTALLDIR="C:\mysql"', ExpandConstant('{tmp}'), SW_HIDE, ewWaitUntilTerminated, iResultCode); if not FileExists(ExpandConstant('{reg:HKLM\SOFTWARE\MySQL AB\MySQL Server 5.5,Location}\bin\mysql.exe')) then begin MsgBox('Something went wrong! Installation should be terminated', mbInformation, MB_OK); Result := false; end; end; end; |