示例:检测系统版本信息
将以下代码拷贝到 test.iss文件中,在目录下再放置一个MyApp.exe,即可以使用innosetup生成一个测试程序。
[Code]
var
Win10System: Boolean;
function MyBoolToStr(Value : Boolean) : String;
begin
if Value then
Result := 'yes'
else
Result := 'no';
end;
function MyDateTime() : String;
begin
result := GetDateTimeString('yyyy-mm-dd hh:nn:ss', '-', ':');
end;
function WriteMyInstallLog(installPath:String; sLog:String) : Boolean;
var
t_FileStream : TFileStream;
AFileName : String;
BFileName : String;
CFileName : String;
t_tmpexe : String;
t_sContent : String;
begin
if(not DirExists(ExpandConstant(installPath))) then
begin
exit;
end;
AFileName := ExpandConstant(installPath + '\win_install.log');
if (FileExists(AFileName)) then
begin
t_FileStream := TFileStream.Create(AFileName,fmOpenWrite);
end else begin
t_FileStream := TFileStream.Create(AFileName,fmCreate);
end;
t_FileStream.Seek(0, soFromEnd);
t_sContent := MyDateTime() + ' ' + sLog + #13#10;
t_FileStream.Write(t_sContent, Length(t_sContent));
t_FileStream.Free;
end;
function GetWindowsSystemVersion(): Integer;
var
Version: TWindowsVersion;
begin
GetWindowsVersionEx(Version);
WriteMyInstallLog(ExpandConstant('d:\'), 'Version.Major' + IntToStr(Version.Major));
WriteMyInstallLog(ExpandConstant('d:\'), 'Version.Minor' + IntToStr(Version.Minor));
if (Version.Major = 5) and (Version.Minor = 0) then
begin
Result := 1; // Windows 2000
end
else if (Version.Major = 5) and (Version.Minor = 1) then
begin
Result := 2; // Windows XP
end
else if (Version.Major = 5) and (Version.Minor = 2) then
begin
Result := 3; // Windows 2003
end
else if (Version.Major = 6) and (Version.Minor = 0) then
begin
Result := 4; // Windows 2008 or Windows Vista
end
else if (Version.Major = 6) and (Version.Minor = 1) then
begin
Result := 5; // Windows 7 or Windows 2008R2
end
else if (Version.Major = 6) and (Version.Minor = 2) then
begin
if (Win10System = True) then
begin
Result := 10;
end
else
begin
Result := 6;
end;
end;
end;
[Setup]
AppName=MyApp
AppVersion=1.0
DefaultDirName={pf}\MyApp
OutputDir=Output
OutputBaseFilename=MyAppSetup
Compression=lzma
SolidCompression=yes
WizardStyle=modern
DisableWelcomePage=yes
DisableReadyPage=yes
DisableFinishedPage=yes
DisableProgramGroupPage=yes
UninstallDisplayIcon={app}\MyApp.exe
PrivilegesRequired=admin
[Files]
Source: "MyApp.exe"; DestDir: "{app}"
[Icons]
Name: "{commondesktop}\MyApp"; Filename: "{app}\MyApp.exe"; WorkingDir: "{app}"; IconFilename: "{app}\MyApp.exe";
[Run]
Filename: "{app}\MyApp.exe"; Flags: postinstall shellexec
[Code]
function InitializeSetup(): Boolean;
begin
GetWindowsSystemVersion();
end;