Inno Setup可以在程序安裝時,通過檢查註冊表判斷出VS2005運行環境是否已經安裝[其他版本類似],如果沒有安裝,則將其安裝。
#define MySourceDir "E:\MyAppSourceRoot"
[Files]
; VC Redistribute
Source: "{#MySourceDir}\vc2005redist\vcredist_x86.exe"; DestDir: "{tmp}"; Check: NeedInstallVC8SP1
[Code]
var
vc8SP1Missing: Boolean;
function NeedInstallVC8SP1(): Boolean;
begin
Result := vc8SP1Missing;
end;
function InitializeSetup(): Boolean;
begin
// 這裏,不同版本運行環境對應的GUID不同
if RegValueExists(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{710f4c1c-cc18-4c49-8cbf-51240c89a1a2}', 'Version') // Microsoft Visual C++ 2005 Redistributable X86 [XP/Win7 32位 V8.0.61001]
or RegValueExists(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{ad8a2fa1-06e7-4b0d-927d-6e54b3d31028}', 'Version') // Microsoft Visual C++ 2005 Redistributable X64 [Win7 64位 V8.0.61000]
or RegValueExists(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{071C9B48-7C32-4621-A0AC-3F809523288F}', 'Version') // Microsoft Visual C++ 2005 SP1 Redistributable X64 [Win7 64位 V8.0.56336]
then
begin
vc8SP1Missing := false;
end
else
begin
vc8SP1Missing := true;
end;
result := true;
end;
[Run]
Filename: "{tmp}\vcredist_x86.exe"; Parameters: /q; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: "Install Microsoft Visual C++ 2005 Runtime ..."; Check: NeedInstallVC8SP1