innosetup简短的测试程序

示例:检测系统版本信息

将以下代码拷贝到  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;


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值