이 블로그 검색

2019년 6월 2일 일요일

Inno Setup(이노셋업) .Net Framework 버전 확인 / 설치

function CheckWindows10: Boolean;
var
  Version: TWindowsVersion;
begin
  GetWindowsVersionEx(Version);
  if Version.Major >= 10 then
  begin
    Result:=True;
  end
  else
  begin
    Result:=False;
  end;
end;

function CheckWindows8: Boolean;
begin
  Result := (GetWindowsVersion >= $06030000) and (GetWindowsVersion <= $0603FFFF);
end;

function IsDotNetDetected(version: string; service: cardinal):boolean;
// Indicates whether the specified version and service pack of the .NET Framework is installed.
//
// version -- Specify one of these strings for the required .NET Framework version:
//    'v1.1.4322'     .NET Framework 1.1
//    'v2.0.50727'    .NET Framework 2.0
//    'v3.0'          .NET Framework 3.0
//    'v3.5'          .NET Framework 3.5
//    'v4\Client'     .NET Framework 4.0 Client Profile
//    'v4\Full'       .NET Framework 4.0 Full Installation
//    'v4.5'          .NET Framework 4.5
//
// service -- Specify any non-negative integer for the required service pack level:
//    0               No service packs required
//    1, 2, etc.      Service pack 1, 2, etc. required
var
    key: string;
    install, release, serviceCount: cardinal;
    check45, success: boolean;

begin
    // .NET 4.5 installs as update to .NET 4.0 Full
    if version = 'v4.5' then begin
        version := 'v4\Full';
        check45 := true;
    end else
        check45 := false;

    // installation key group for all .NET versions
    key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + version;

    // .NET 3.0 uses value InstallSuccess in subkey Setup
    if Pos('v3.0', version) = 1 then begin
        success := RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install);
    end else begin
        success := RegQueryDWordValue(HKLM, key, 'Install', install);
    end;

    // .NET 4.0/4.5 uses value Servicing instead of SP
    if Pos('v4', version) = 1 then begin
        success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount);
    end else begin
        success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount);
    end;

    // .NET 4.5 uses additional value Release
    if check45 then begin
        success := success and RegQueryDWordValue(HKLM, key, 'Release', release);
        success := success and (release >= 378389);
    end;

    result := success and (install = 1) and (serviceCount >= service);
end;
   
function CheckForFramework(): Boolean;
begin
    if not IsDotNetDetected('v4.5',0) then begin
      Result := True;
    end else begin
      Result := False;
    end;
end;               

var
  LightMsgPage: TOutputMsgWizardPage;

procedure InitializeWizard;
begin
if not IsDotNetDetected('v4.5',0) then begin
  { Create the pages }
  if GetUILanguage = 1042 then begin
  LightMsgPage := CreateOutputMsgPage(wpWelcome,
    '.NET Information', '.NET 설치가 필요합니다.',
    '경고: PC에 설치되어 있는 닷넷 버전이 낮습니다. '#13 +
    '현재 버전의 닷넷 프레임워크에서는 더한 타블렛 드라이버가 정상 동작하지 않습니다.'#13 +
    '그래서 상위버전의 닷넷 프레임워크를 설치할 것입니다.'#13#13 +
    '만약 원하지 않을 경우 취소 버튼을 눌러 설치를 종료하세요.');
  end else begin
  LightMsgPage := CreateOutputMsgPage(wpWelcome,
    '.NET Information', '.NET installation is required.',
    'Note: .Net version that is currently installed on your PC is low. '#13 +
    'The later version of the .Net Framework is required to the normal operation of the TheHan Tablet Driver.'#13 +
    'So it will install the .Net Framework of higher versions.'#13#13 +
    'If you do not want, press the Cancel button.');
  end;
  end;
end; 

Inno Setup (이노셋업) 이전 버전 확인 후 Uninstall / Install

function GetUninstallString: string;
var
  sUnInstPath: string;
  sUnInstallString: String;
begin
  Result := '';
  sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{{B77EBEF8-649A-4420-8EC9-14E43D09072D}_is1'); //Your App GUID/ID
  sUnInstallString := '';
  if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
    RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
  Result := sUnInstallString;
end;

function IsUpgrade: Boolean;
begin
  Result := (GetUninstallString() <> '');
end;

function InitializeSetup: Boolean;
var
  V: Integer;
  iResultCode: Integer;
  sUnInstallString: string;
begin
  Result := True; // in case when no previous version is found
  if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\{B77EBEF8-649A-4420-8EC9-14E43D09072D}_is1', 'UninstallString') then  //Your App GUID/ID
  begin
    V := MsgBox(ExpandConstant('An old version of app was detected. Do you want to uninstall it?'), mbInformation, MB_YESNO); //Custom Message if App installed
    if V = IDYES then
    begin
      sUnInstallString := GetUninstallString();
      sUnInstallString :=  RemoveQuotes(sUnInstallString);
      Exec(ExpandConstant(sUnInstallString), '', '', SW_SHOW, ewWaitUntilTerminated, iResultCode);
      Result := True; //if you want to proceed after uninstall
      //Exit; //if you want to quit after uninstall
    end
    else
      Result := False; //when older version present and not uninstalled
  end;
end;