📄 codeexample1.iss
字号:
; -- CodeExample1.iss --
;
; This script shows various things you can achieve using a [Code] section
[Setup]
AppName=My Program
AppVerName=My Program version 1.5
DefaultDirName={code:MyConst}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
InfoBeforeFile=Readme.txt
[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Check: MyProgCheck; BeforeInstall: BeforeMyProgInstall('MyProg.exe'); AfterInstall: AfterMyProgInstall('MyProg.exe')
Source: "MyProg.hlp"; DestDir: "{app}"; Check: MyProgCheck; BeforeInstall: BeforeMyProgInstall('MyProg.hlp'); AfterInstall: AfterMyProgInstall('MyProg.hlp')
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
[Code]
var
MyProgChecked: Boolean;
MyProgCheckResult: Boolean;
FinishedInstall: Boolean;
function InitializeSetup(): Boolean;
begin
Result := MsgBox('InitializeSetup:' #13#13 'Setup is initializing. Do you really want to start setup?', mbConfirmation, MB_YESNO) = idYes;
if Result = False then
MsgBox('InitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
end;
procedure DeinitializeSetup();
var
FileName: String;
ResultCode: Integer;
begin
if FinishedInstall then begin
if MsgBox('DeinitializeSetup:' #13#13 'The [Code] scripting demo has finished. Do you want to uninstall My Program now?', mbConfirmation, MB_YESNO) = idYes then begin
FileName := ExpandConstant('{uninstallexe}');
if not Exec(FileName, '', '', SW_SHOWNORMAL, ewNoWait, ResultCode) then
MsgBox('DeinitializeSetup:' #13#13 'Execution of ''' + FileName + ''' failed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
end else
MsgBox('DeinitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
FinishedInstall := True;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
begin
case CurPageID of
wpSelectDir:
MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardDirValue + '''.', mbInformation, MB_OK);
wpSelectProgramGroup:
MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardGroupValue + '''.', mbInformation, MB_OK);
wpReady:
begin
if MsgBox('NextButtonClick:' #13#13 'Using the script, files can now be extracted before the installation starts. For example we could extract ''MyProg.exe'' now and run it.' #13#13 'Do you want to do this?', mbConfirmation, MB_YESNO) = idYes then begin
ExtractTemporaryFile('myprog.exe');
if not Exec(ExpandConstant('{tmp}\myprog.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
MsgBox('NextButtonClick:' #13#13 'The file could not be executed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
end;
BringToFrontAndRestore();
MsgBox('NextButtonClick:' #13#13 'The normal installation will now start.', mbInformation, MB_OK);
end;
end;
Result := True;
end;
function ShouldSkipPage(PageID: Integer): Boolean;
begin
{ Skip wpInfoBefore page; show all others }
case PageID of
wpInfoBefore:
Result := True;
else
Result := False;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
case CurPageID of
wpWelcome:
MsgBox('CurPageChanged:' #13#13 'Welcome to the [Code] scripting demo. This demo will show you some possibilities of the scripting support.' #13#13 'The scripting engine used is RemObjects Pascal Script by Carlo Kok. See http://www.remobjects.com/?ps for more information.', mbInformation, MB_OK);
wpFinished:
MsgBox('CurPageChanged:' #13#13 'Welcome to final page of this demo. Click Finish to exit.', mbInformation, MB_OK);
end;
end;
function MyProgCheck(): Boolean;
begin
if not MyProgChecked then begin
MyProgCheckResult := MsgBox('MyProg:' #13#13 'Do you want to install MyProg.exe and MyProg.hlp to ' + ExtractFilePath(CurrentFileName) + '?', mbConfirmation, MB_YESNO) = idYes;
MyProgChecked := True;
end;
Result := MyProgCheckResult;
end;
procedure BeforeMyProgInstall(S: String);
begin
MsgBox('BeforeMyProgInstall:' #13#13 'Setup is now going to install ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;
procedure AfterMyProgInstall(S: String);
begin
MsgBox('AfterMyProgInstall:' #13#13 'Setup just installed ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;
function MyConst(Param: String): String;
begin
Result := ExpandConstant('{pf}');
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -