我目前在 Inno 脚本的这一部分中有这个
[Run]
Filename: {app}\bin\vcredist_x86.exe; Parameters: "/q:a /c:""VCREDI~3.EXE /q:a /c:""""msiexec /i vcredist.msi /qn"""" """; WorkingDir: {app}\bin; StatusMsg: Installing Visual Studio 2010 C++ CRT Libraries...
它将在应用程序安装期间运行 vcredist 安装程序。但这样做的问题是,如果用户已经安装了它,它会抛出类似
- 修复/移除
- 已检测到较新版本
有什么方法可以避免这种情况并且只在需要时运行这个安装程序吗?我应该向 Inno 脚本添加什么?
编辑:
在@John 链接的帮助下,我添加了以下功能
我还使用了 this site引用获取 visual studio 2010 crt++ 产品代码并使用注册表中的 Uninstall 文件夹来检测其是否已安装。
function InitializeSetup(): Boolean;
var
ErrorCode: Integer;
RedistInstalled : Boolean;
Result1 : Boolean;
begin
RedistInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{196BB40D-1578-3D01-B289-BEFC77A11A1E}');
if RedistInstalled then
begin
Result := true;
end else
begin
RedistInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{196BB40D-1578-3D01-B289-BEFC77A11A1E}');
if RedistInstalled then
begin
Result := true;
end else
begin
Result1 := MsgBox('This setup requires Microsoft Visual C++ 2010 Redistributable Package (x86). Please install Visual C++ 2010 Redistributable Package (x86) and run this setup again. '#13#10' '#13#10'Do you want to download Microsoft Visual C++ 2010 Redistributable Package (x86) now?',
mbConfirmation, MB_YESNO) = idYes;
if Result1 =false then
begin
Result:=false;
end else
begin
Result:=false;
ShellExec('open',
'http://download.microsoft.com/download/5/B/C/5BC5DBB3-652D-4DCE-B14A-475AB85EEF6E/vcredist_x86.exe',
'','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
end;
end;
end;
end;
如果安装程序在下载/安装后继续,或者我可以以某种方式调整我以前运行的代码,包括(使用设置)安装程序,那还是很好的:
[Run]
Filename: {app}\bin\vcredist_x86.exe; Parameters: "/q:a /c:""VCREDI~3.EXE /q:a /c:""""msiexec /i vcredist.msi /qn"""" """; WorkingDir: {app}\bin; StatusMsg: Installing Visual Studio 2010 C++ CRT Libraries...
但这仍然足够好。
最佳答案
我遵循“官方”MS 方式 https://stackoverflow.com/a/199783/866333 .还没有完全流行起来,但对我有用。
参见 Inno Setup: Verify that .NET 4.0 is installed用于仅检测一个版本的工作代码。
这是我实际使用的代码的最佳示例:http://www.vincenzo.net/isxkb/index.php?title=.NET_-_Detect_framework
以上所有内容都针对 .NET 框架。对于 VCRT,我将从 VC2010 中提取可再发行组件,并让 InnoSetup 将内容复制到应用程序的目标安装目录。这样系统文件就不会被更改。
关于c++ - InnoSetup - 检查是否安装了 visual studio 2010 crt redist,如果没有则运行安装程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10982468/