Inno Setup[1] with Delphi written, its official website also provides free download source program. Although it can not be compared with InstallShield This kind of dinosaur-grade installation software, but also deserves to be a rising star. Inno Setup is a free installation software, small, simple, beautiful is its biggest feature, support Pascal script, can quickly produce a standard Windows2000-style installation interface, enough to complete the general installation tasks.
Use Innosetup as a sample script (. iss file) for the application installation package, depending on the documentation that came with the innosetup, as if it were a Pascal-written script.
Example 1 (application. exe, client Installation):
; {089d6802-6cd3-4e45-b8d5-ac9ed99ce371}; The script is generated by the Inno Setup Script Wizard!
; For more information about creating a Inno Setup script file, check out the Help documentation!
[Setup]
; Note: The value of AppID identifies the application individually.
; Do not use the same AppID value for the other setup programs.
; (Generate a new GUID, click Tools | Build the GUID in the IDE.) )
APPID={{5E012E21-42EE-4840-A000-35F9FAB886E9}
Appname=ais_client
Appvername=ais_client
Apppublisher= Company Name
Defaultdirname={pf}\ais_client
Defaultgroupname=ais_client
Outputbasefilename=ais_client
Compression=lzma
Solidcompression=yes
Setupiconfile=d:\ais\ais Packaging Program \aisgui.ico
Licensefile=c:\documents and settings\administrator\ desktop \ License Agreement. txt
[Languages]
Name: "Chinesesimp"; Messagesfile: "COMPILER:DEFAULT.ISL"
[Files]
Source: "D:\AIS\AIS packaging program \ais_client_exe\*"; DestDir: "{app}"; Flags:ignoreversion Recursesubdirs Createallsubdirs
; Note: Do not use "flags:ignoreversion" on any shared system files
[Tasks]
Name: "Desktopicon"; Description: "{Cm:createdesktopicon}"; Groupdescription: "{cm:additionalicons}"
[Icons]
Name: "{Group}\ais client"; Filename: "{app}\aisgui.exe"
Name: "{Group}\ais client parameter Configuration Tool"; Filename: "{app}\clientconfig.exe"
Name: "{Group}\ais service Setup tool"; Filename: "{app}\serviceipmanage.exe"
Name: "{Group}\ais Database parameter Configuration Tool"; Filename: "{app}\databaseconfig.exe"
; Name: "{group}\-gated service side"; Filename: "{app}\access_server\securityware.exe"
Add a delete shortcut to the book in the Start menu, all programs.
Name: "{group}\ uninstall"; Filename: {Uninstallexe}
Name: "{Commondesktop}\ais client"; Filename: "{App}\aisgui.exe"; Tasks:desktopicon
; Name: "{commondesktop}\-gated service side"; Filename: "{App}\access_server\securityware.exe"; Tasks:desktopicon
[Run]
; Filename: "{App}\access_server\securityware.exe"; Description: "{Cm:launchprogram,ais}"; Flags:nowait Postinstall skipifsilent shellexec
Filename: "{App}\aisgui.exe"; Description: "{Cm:launchprogram,ais}"; Flags:nowait Postinstall skipifsilent shellexec
[Registry]
; Add boot Boot
ROOT:HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; valuetype:string; ValueName: "AIS"; Valuedata: "{App}\aisgui.exe"; Flags:uninsdeletevalue
[Code]
{Determine if the main program is running when unloading}
Var
Is_sys, Is_value:integer;
S_syschar, S_currentchar, S_current,s_sys, s,resultstr:string;
I, Closenum:integer;
Errorcode:integer;
guid_names,window_name:tarrayofstring;
Bool:boolean;
Const appname= ' {5e012e21-42ee-4840-a000-35f9fab886e9}_is1 ';
{Determine if the main program is running before the program is installed}
function Initializesetup (): Boolean;
Var
Resultcode:integer;
Begin
If Reggetsubkeynames (HKEY_LOCAL_MACHINE, ' Software\microsoft\windows\currentversion\uninstall ', Guid_names) then
Begin
For i:=0 to Getarraylength (guid_names)-1 do
Begin
S: = Guid_names[i];
This key was found in the registry
If Appname=guid_names[i] Then
Begin
BOOL: = Regquerystringvalue (HKEY_LOCAL_MACHINE, ' software\microsoft\windows\currentversion\uninstall\ ' +S, ' UninstallString ', resultstr);
ResultStr: = Removequotes (RESULTSTR);
if BOOL Then
Begin
If MsgBox (' Setup has detected that the current computer has an AIS client installed. ' #13 #13 ' Do you want to uninstall the AIS client? ', mbconfirmation, mb_yesno) = Idyes Then
Shellexec (' ', Expandconstant (' {app}\unins000.exe '), ', ', ' Sw_show, ewnowait, ResultCode);
Begin
Exec (Removequotes (RESULTSTR), ",", Sw_show, ewwaituntilterminated, ResultCode);
Result: = false;
End
End
Break
End
Else
ZDX 5.8 Determine if an installer has been opened
Begin
If Findwindowbywindowname (' Install-ais_client ') <>0 Then
Begin
MsgBox (' Installer has detected that another installer is already running ', mbconfirmation, MB_OK);
Result: = false;
Break
End
End
End
If i= getarraylength (guid_names) Then
Result: = true;
End
Else
Result: = true;
End
Delete the folder that was copied to the system when the user clicked Cancel
Procedure Cancelbuttonclick (Curpageid:integer; var Cancel, Confirm:boolean);
Begin
End;
Uninstalling the password verification function
function Askpassword (): Boolean;
Var
Form:tsetupform;
OKButton, Cancelbutton:tbutton;
Pwdedit:tpasswordedit;
Begin
Result: = false;
Form: = Createcustomform ();
Try
Form.clientwidth: = ScaleX (256);
Form.clientheight: = ScaleY (100);
Form.caption: = ' password Authentication ';
Form.bordericons: = [Bisystemmenu];
Form.borderstyle: = Bsdialog;
Form.center;
OKButton: = Tbutton.create (Form);
Okbutton.parent: = Form;
Okbutton.width: = ScaleX (75);
Okbutton.height: = ScaleY (23);
Okbutton.left: = Form.clientwidth-scalex (75 + 6 + 75 + 50);
Okbutton.top: = Form.clientheight-scaley (23 + 10);
Okbutton.caption: = ' OK ';
Okbutton.modalresult: = Mrok;
Okbutton.default: = true;
CancelButton: = Tbutton.create (Form);
Cancelbutton.parent: = Form;
Cancelbutton.width: = ScaleX (75);
Cancelbutton.height: = ScaleY (23);
Cancelbutton.left: = Form.clientwidth-scalex (75 + 50);
Cancelbutton.top: = Form.clientheight-scaley (23 + 10);
Cancelbutton.caption: = ' Cancel ';
Cancelbutton.modalresult: = Mrcancel;
Cancelbutton.cancel: = True;
Pwdedit: = Tpasswordedit.create (Form);
Pwdedit.parent: = Form;
Pwdedit.width: = ScaleX (210);
Pwdedit.height: = ScaleY (23);
Pwdedit.left: = ScaleX (23);
Pwdedit.top: = ScaleY (23);
Form.activecontrol: = Pwdedit;
If Form.showmodal () = Mrok Then
Begin
Result: = Pwdedit.text = ' bw12345678 ';
If not Result then
MsgBox (' Password error ', mbinformation, MB_OK);
End
Finally
Form.free ();
End
End
When uninstalling a program, determine if it is running
function Initializeuninstall (): Boolean;
Begin
Begin
Password verification
Result: = Askpassword ();
Result: = TRUE;
deltree (Expandconstant (' {app}\* '), False, True, true);
End
End
Prompt to restart your computer when you are finished uninstalling
function Uninstallneedrestart (): Boolean;
Begin
Result: = False;
deltree (Expandconstant (' {app}\* '), False, True, true);
deltree (Expandconstant (' {app} '), True, true, true);
End
Example 2 (Windows service, server-side installation):
; {089d6802-6cd3-4e45-b8d5-ac9ed99ce371}; The script is generated by the Inno Setup Script Wizard!
; For more information about creating a Inno Setup script file, check out the Help documentation!
[Setup]
; Note: The value of AppID identifies the application individually.
; Do not use the same AppID value for the other setup programs.
; (Generate a new GUID, click Tools | Build the GUID in the IDE.) )
APPID={{D0D0B722-C6F9-4A89-AB56-1417B9BD1400}
Appname=ais_server
Appvername=ais_server
Apppublisher= Company Name
Defaultdirname={pf}\ais_server
Defaultgroupname=ais_server
Outputbasefilename=ais_server
Compression=lzma
Solidcompression=yes
Setupiconfile=d:\ais\ais Packaging Program \aisgui.ico
Licensefile=c:\documents and settings\administrator\ desktop \ License Agreement. txt
[Languages]
Name: "Chinesesimp"; Messagesfile: "COMPILER:DEFAULT.ISL"
[Files]
Source: "D:\AIS\AIS packaging program \ais_server_exe\*"; DestDir: "{app}"; Flags:ignoreversion Recursesubdirs Createallsubdirs
; Note: Do not use "flags:ignoreversion" on any shared system files
[Tasks]
Name: "Desktopicon"; Description: "{Cm:createdesktopicon}"; Groupdescription: "{cm:additionalicons}"
[Icons]
Name: "{Group}\ais Server parameter Configuration Tool"; Filename: "{app}\serviceconfig.exe"
; Name: "{Group}\ais client"; Filename: "{app}\ais_client_exe\aisgui.exe"
; Name: "{group}\-gated service side"; Filename: "{app}\access_server\securityware.exe"
Add a delete shortcut to the book in the Start menu, all programs.
Name: "{group}\ uninstall"; Filename: {Uninstallexe}
; Name: "{Commondesktop}\ais client"; Filename: "{App}\ais_client_exe\aisgui.exe"; Tasks:desktopicon
; Name: "{commondesktop}\-gated service side"; Filename: "{App}\access_server\securityware.exe"; Tasks:desktopicon
[Run]
; Filename: "{App}\access_server\securityware.exe"; Description: "{Cm:launchprogram,ais}"; Flags:nowait Postinstall skipifsilent shellexec
; Filename: "{App}\ais_client_exe\aisgui.exe"; Description: "{Cm:launchprogram,ais}"; Flags:nowait Postinstall skipifsilent shellexec
[Registry]
; Add boot Boot
; ROOT:HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; valuetype:string; ValueName: "BWQC"; Valuedata: "{App}\msrv.exe"; Flags:uninsdeletevalue
[Code]
{Determine if the main program is running when unloading}
Var
Is_sys, Is_value:integer;
S_syschar, S_currentchar, S_current,s_sys, s,resultstr:string;
I, Closenum:integer;
Errorcode:integer;
guid_names,window_name:tarrayofstring;
Bool:boolean;
Const appname= ' {d0d0b722-c6f9-4a89-ab56-1417b9bd1400}_is1 ';
{Determine if the main program is running before the program is installed}
function Initializesetup (): Boolean;
Var
Resultcode:integer;
Begin
If Reggetsubkeynames (HKEY_LOCAL_MACHINE, ' Software\microsoft\windows\currentversion\uninstall ', Guid_names) then
Begin
For i:=0 to Getarraylength (guid_names)-1 do
Begin
S: = Guid_names[i];
This key was found in the registry
If AppName = Guid_names[i] Then
Begin
BOOL: = Regquerystringvalue (HKEY_LOCAL_MACHINE, ' software\microsoft\windows\currentversion\uninstall\ ' +S, ' UninstallString ', resultstr);
ResultStr: = Removequotes (RESULTSTR);
if BOOL Then
Begin
If MsgBox (' Setup detects that the current computer already has Ais_server installed. ' #13 #13 ' Do you want to uninstall Ais_server? ', mbconfirmation, mb_yesno) = Idyes Then
Shellexec (' ', Expandconstant (' {app}\unins000.exe '), ', ', ' Sw_show, ewnowait, ResultCode);
Begin
Exec (Removequotes (RESULTSTR), ",", Sw_show, ewwaituntilterminated, ResultCode);
Result: = false;
End
End
Break
End
Else
ZDX 5.8 Determine if an installer has been opened
Begin
If Findwindowbywindowname (' Install-ais_server ') <>0 Then
Begin
MsgBox (' Installer has detected that another installer is already running ', mbconfirmation, MB_OK);
Result: = false;
Break
End
End
End
If I = Getarraylength (guid_names) Then
Result: = true;
End
Else
Result: = true;
End
Delete the folder that was copied to the system when the user clicked Cancel
Procedure Cancelbuttonclick (Curpageid:integer; var Cancel, Confirm:boolean);
Begin
End;
Uninstalling the password verification function
function Askpassword (): Boolean;
Var
Form:tsetupform;
OKButton, Cancelbutton:tbutton;
Pwdedit:tpasswordedit;
Begin
Result: = false;
Form: = Createcustomform ();
Try
Form.clientwidth: = ScaleX (256);
Form.clientheight: = ScaleY (100);
Form.caption: = ' password Authentication ';
Form.bordericons: = [Bisystemmenu];
Form.borderstyle: = Bsdialog;
Form.center;
OKButton: = Tbutton.create (Form);
Okbutton.parent: = Form;
Okbutton.width: = ScaleX (75);
Okbutton.height: = ScaleY (23);
Okbutton.left: = Form.clientwidth-scalex (75 + 6 + 75 + 50);
Okbutton.top: = Form.clientheight-scaley (23 + 10);
Okbutton.caption: = ' OK ';
Okbutton.modalresult: = Mrok;
Okbutton.default: = true;
CancelButton: = Tbutton.create (Form);
Cancelbutton.parent: = Form;
Cancelbutton.width: = ScaleX (75);
Cancelbutton.height: = ScaleY (23);
Cancelbutton.left: = Form.clientwidth-scalex (75 + 50);
Cancelbutton.top: = Form.clientheight-scaley (23 + 10);
Cancelbutton.caption: = ' Cancel ';
Cancelbutton.modalresult: = Mrcancel;
Cancelbutton.cancel: = True;
Pwdedit: = Tpasswordedit.create (Form);
Pwdedit.parent: = Form;
Pwdedit.width: = ScaleX (210);
Pwdedit.height: = ScaleY (23);
Pwdedit.left: = ScaleX (23);
Pwdedit.top: = ScaleY (23);
Form.activecontrol: = Pwdedit;
If Form.showmodal () = Mrok Then
Begin
Result: = Pwdedit.text = ' bw12345678 ';
If not Result then
MsgBox (' Password error ', mbinformation, MB_OK);
End
Finally
Form.free ();
End
End
Procedure curstepchanged (curstep:tsetupstep);//Add environment variable
var
resultcode:integer;
Begin
If curstep = Sspostinstall then
begin
shellexec (", Expandconstant (' {app}\serviceinstall.exe '),
'-is ais_server ' + expandconstant (' {app}\ais_server.exe ') + ' "', ' ', Sw_hide, ewwaituntilterminated, ResultCode);
end;
End;
Procedure curuninstallstepchanged (Curuninstallstep:tuninstallstep);
Var
Resultcode:integer;
Begin
If Curuninstallstep = Usuninstall Then
Begin
Shellexec (' ', Expandconstant (' {app}\serviceinstall.exe '),
'-u ais_server ' + expandconstant (' {app}\ais_server.exe ') + ' "', ' ', Sw_hide, ewwaituntilterminated, ResultCode);
End
End
When uninstalling a program, determine if it is running
function Initializeuninstall (): Boolean;
Begin
Begin
Password verification
Result: = Askpassword ();
Result: = TRUE;
deltree (Expandconstant (' {app}\* '), False, True, true);
End
End
Prompt to restart your computer when you are finished uninstalling
function Uninstallneedrestart (): Boolean;
Begin
Result: = False;
deltree (Expandconstant (' {app}\* '), False, True, true);
deltree (Expandconstant (' {app} '), True, true, true);
End
Installer---inno Setup