使用inno setup 检测vcredist_x86.exe是否已经存在并安装
[Files]
Source: ntviewer_xul\vcredist_x86.exe; DestDir: {tmp}; Check: NeedInstallVC8
[Run]
Filename: {tmp}\vcredist_x86.exe; Parameters: /q; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: 安装微软 Visual C++ 运行时库 ...; Check: NeedInstallVC8
[Code]
function MsiQueryProductState(ProductCode: string): integer;
external 'MsiQueryProductStateA@msi.dll';
function MsiConfigureProduct(ProductCode: string;
iInstallLevel: integer; eInstallState: integer): integer;
external 'MsiConfigureProductA@msi.dll';
const
INSTALLSTATE_DEFAULT = 5;
INSTALLLEVEL_MAXIMUM = $ffff;
INSTALLSTATE_ABSENT = 2;
const
VCREDIST_X86 ='{7299052b-02a4-4627-81f2-1818da5d550d}';
function IsMsiProductInstalled(const ProductId: string): boolean;
begin
Result := MsiQueryProductState(ProductId) = INSTALLSTATE_DEFAULT;
end;
function UninstallMsiProduct(const ProductId: string): boolean;
begin
Result := false;
if not IsMsiProductInstalled(ProductId) then exit;
Result := MsiConfigureProduct(ProductId, INSTALLLEVEL_MAXIMUM,
INSTALLSTATE_ABSENT) = 0;
end;
var vc8Missing: Boolean;
function NeedInstallVC8(): Boolean;
begin
Result := not vc8Missing;
end;
function InitializeSetup(): Boolean;
var version: Cardinal;
begin
vc8Missing :=IsMsiProductInstalled(VCREDIST_X86);
result := true;
end;