Once the system has been developed, it is often necessary to create an installation package to sell to the user. With the Inno Setup Wizard you can make a simple installation package, but if you want to make a good installation package, you may encounter some trouble, today finally took time to solve the problem, Inno Setup packaging. Specific as follows:
1. When uninstalling, how to tell if the application is running
Innosetup provides a variable Appmutex that holds the name of the mutex for the application. Many applications now run as unique instances. This avoids configuration files being incorrectly modified and many other derivative issues. A mutex is usually created with WindowsAPI Createmuex, and the installation package uninstalls to determine whether Appmutex is already occupied. Waits and prompts the user to close the application if it is occupied. If the application is running, usually the EXE file and the DLL being used are not removed and the uninstallation is not complete.
In the Inno Setup Compile configuration, myprogramsmutexname is defined as "ityujian-a75dec53-783f-4425-8431-24d83bd4ce5f" and the string needs to be used in the packaged EXE file.
#define MYPROGRAMSMUTEXNAME "ityujian-a75dec53-783f-4425-8431-24d83bd4ce5f"
[Setup]
appmutex={#MyProgramsMutexName}
2. How to prompt the user whether to delete the configuration file
Inno Setup provides script language support to write functions in the [Code] section using Pascal script and Inno Setup to provide event responses. When unloaded, the function is called
Procedure curuninstallstepchanged (Curuninstallstep:tuninstallstep);
Begin
If curuninstallstep = Usuninstall THEN BEGIN
If MsgBox (' Do-want-delete all config files and log files? ', mbconfirmation, mb_yesno) = Idyes
Then DelFiles ();
End
End
This is the Unload event function provided by Inno Setup, if Curuninstallstep = Usuninstall to determine if it is being unloaded,
If you are uninstalling, you need to decide whether to delete the configuration file, the application I developed uses the INI file storage configuration. MsgBox (' Do-want-delete all config files and log files? ', Mbconfirmation, Mb_yesno) is used to pop up a message box prompting the user to choose whether to delete the file.
The function DelFiles () is a custom function that is used to delete files and directories.
Expandconstant is used to get the variable value, FileExists is used to determine whether the file exists; DeleteFile is used to delete files;
Direxists is used to check if a directory exists; deltree is used to delete directories and files inside
Procedure DelFiles ();
Begin
If FileExists (Expandconstant (' {app} ') + ' config.ini ') then DeleteFile (Expandconstant (' {app} ') + ' config.ini ');
If FileExists (Expandconstant (' {app} ') + ' Log.txt ') then DeleteFile (Expandconstant (' {app} ') + ' log.txt ');
If Direxists (Expandconstant (' {app} ') + ' users ') then deltree (Expandconstant (' {app} ') + ' users ', True, true, true);
End
Inno Setup compiles the configuration file as follows, for reference:
; Script generated by the Inno Setup Script Wizard.
; See the documentation for DETAILS on CREATING inno SETUP SCRIPT files!
#define MYAPPNAME "Ityujian"  
; application name
#define Myappversion "1.0"  
; version number
#define Myapppublisher "Jianyu Studio"  
; publisher name
#define MYAPPURL "http://www.cnblogs.com/ityujian/"
; the company's website
#define MYAPPEXENAME "Ityujian.exe"  
; exe filename
#define MYPROGRAMSMUTEXNAME " ityujian-a75dec53-783f-4425-8431-24d83bd4ce5f " 
; the mutex used in the application that is used to determine whether the application is executing
[setup]
; Note:the value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers to other applications.
; (to generate a new GUID, click Tools | Generate GUID inside the IDE.)
appid={{eccf74cd-48ba-4000-988b-18e965893bd6}
appname={#MyAppName}
appversion={# myappversion}
; appvername={#MyAppName} {#MyAppVersion}
apppublisher={#MyAppPublisher}
apppublisherurl={# myappurl}
appsupporturl={#MyAppURL}
appupdatesurl={#MyAppURL}
defaultdirname={pf}{# myappname}
defaultgroupname={#MyAppName}
allownoicons=yes
Outputbasefilename=setup
setupiconfile=.ityujian.ico
; Setupiconfile is the icon file of EXE after packaging
compression=lzma
solidcompression=yes
appmutex={# myprogramsmutexname}
; Appmutex is a mutex that needs to be packaged by an application, and before it is unloaded, it is determined whether the Appmutex is already occupied, and if the application is running if it is occupied, close the
[Languages]
Name: "中文版"; 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: "GdiPlus.dll"; DestDir: "{app}"; flags:ignoreversion
Source: "Ityujian.exe"; DestDir: "{app}"; flags:ignoreversion
; Source describes the exe file location that needs to be packaged, Destdir describes the relative position of the EXE file at installation
Source: "ityujian.pdb"; DestDir: "{app}"; flags:ignoreversion
Source: "users*"; DestDir: "{app}users"; Flags:ignoreversion recursesubdirs createallsubdirs uninsneveruninstall
; the previous sentence is used to hit the users directory into the installation package Uninsneveruninstall Description Uninstall, do not delete the folder
Source: "doc*"; DestDir: "{App}doc"; Flags:ignoreversion recursesubdirs createallsubdirs
; user's Manual in the doc directory is punched into the installation package
; Note:don ' t use "flags:ignoreversion" on any shared system files
[Icons]
Name: "{group}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"
Name: "{group}{cm:programontheweb,{#MyAppName}}"; Filename: "{#MyAppURL}"
Name: "{group}{cm:uninstallprogram,{#MyAppName}}"; Filename: "{Uninstallexe}"
Name: "{commondesktop}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"; Tasks:desktopicon
Name: "{userappdata}microsoftinternet explorerquick launch{#MyAppName}"; Filename: "{app}{#MyAppExeName}"; Tasks:quicklaunchicon
[Uninstalldelete]
Type:dirifempty; Name: "{app}"
; Type:dirifempty indicates that if the directory where the application is installed is not empty, the installation directory is not deleted
[Code]
Procedure DelFiles ();
Begin
If FileExists (Expandconstant (' {app} ') + ' config.ini ') then DeleteFile (Expandconstant (' {app} ') + ' config.ini ');
If FileExists (Expandconstant (' {app} ') + ' Log.txt ') then DeleteFile (Expandconstant (' {app} ') + ' log.txt ');
If Direxists (Expandconstant (' {app} ') + ' users ') then deltree (Expandconstant (' {app} ') + ' users ', True, true, true);
End
Procedure curuninstallstepchanged (Curuninstallstep:tuninstallstep);
Begin
If curuninstallstep = Usuninstall THEN BEGIN
If MsgBox (' Do-want-delete all config files and log files? ', mbconfirmation, mb_yesno) = Idyes
Then DelFiles ();
End
End
After installation:
This article link: http://www.cnblogs.com/ityujian/p/Inno_Setup_Problems.html, reprint please specify
A few questions about installing the Inno setup package