【问题标题】:Inno Setup for Visual C++ Redistributable Package for Visual Studio 2013适用于 Visual Studio 2013 的 Visual C++ 可再发行包的 Inno 设置
【发布时间】:2018-07-08 02:21:37
【问题描述】:

我正在使用位于 http://www.jrsoftware.org/ 的 Inno Setup

我也在使用位于 http://www.codeproject.com/Articles/20868/NET-Framework-Installer-for-InnoSetup 的模块化 InnoSetup 依赖安装程序

我有一个项目需要 Visual C++ Redistributable Package for Visual Studio 2013,位于此处。 http://www.microsoft.com/en-us/download/details.aspx?id=40784

我正在尝试从 Modular Inno Seup Dependency 安装程序修改产品文件。我已将文件从 vcredist2010.iss 复制并修改为 vcredist2013.iss,但问题是每次安装它都会重新下载 C++ 2013 运行时。我认为它不会检测到安装,因此每次都会重新安装。

这是我目前拥有的代码..

// requires Windows 7 Service Pack 1, Windows 8, Windows 8.1, Windows Server 2003, Windows Server 2008 R2 SP1, Windows Server 2008 Service Pack 2, Windows Server 2012, Windows Server 2012 R2, Windows Vista Service Pack 2, Windows XP Service Pack 3
// requires Windows Installer 3.1 or later (??)
// requires Internet Explorer 5.01 or later (??)
// http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992

[CustomMessages]
vcredist2013_title=Visual C++ 2013 Redistributable

en.vcredist2013_size=6.2 MB
de.vcredist2013_size=6,2 MB

en.vcredist2013_size_x64=6.9 MB
de.vcredist2013_size_x64=6,9 MB

;http://www.microsoft.com/globaldev/reference/lcid-all.mspx
en.vcredist2013_lcid=''
de.vcredist2013_lcid='/lcid 1031 '

[Code]
const
    vcredist2013_url = 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe';
    vcredist2013_url_x64 = 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe';


procedure vcredist2013();
var
    version: cardinal;
begin
    RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\VisualStudio\12.0\VC\VCRedist\' + GetString('x86', 'x64',''), 'Installed', version);

    if (version <> 1) then
    AddProduct('vcredist2013' + GetArchitectureString() + '.exe',
            CustomMessage('vcredist2013_lcid') + '/passive /norestart',
            CustomMessage('vcredist2013_title'),
        CustomMessage('vcredist2013_size' + GetArchitectureString()),
            GetString(vcredist2013_url, vcredist2013_url_x64,''),false, false);
end;

有人有更好的方法吗?

谢谢。

更新

这是最新版本。

// requires Windows 7 Service Pack 1, Windows 8, Windows 8.1, Windows Server 2003, Windows Server 2008 R2 SP1, Windows Server 2008 Service Pack 2, Windows Server 2012, Windows Server 2012 R2, Windows Vista Service Pack 2, Windows XP Service Pack 3
// requires Windows Installer 3.1 or later (??)
// requires Internet Explorer 5.01 or later (??)
// http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992
// Thank you (Martyn) https://allthingsconfigmgr.wordpress.com/2013/12/17/visual-c-redistributables-made-simple/
// http://stackoverflow.com/questions/27582762/inno-setup-for-visual-c-redistributable-package-for-visual-studio-2013
// http://stackoverflow.com/questions/11137424/how-to-make-vcredist-x86-reinstall-only-if-not-yet-installed

[CustomMessages]
vcredist2013_title=Visual C++ 2013 Redistribute (32bit)
vcredist2013_title_x64=Visual C++ 2013 Redistribute (64bit)

en.vcredist2013_size=6.2 MB
de.vcredist2013_size=6,2 MB

en.vcredist2013_size_x64=6.9 MB
de.vcredist2013_size_x64=6,9 MB

;http://www.microsoft.com/globaldev/reference/lcid-all.mspx
en.vcredist2013_lcid=''
de.vcredist2013_lcid='/lcid 1031 '

[Code]
#IFDEF UNICODE
    #DEFINE AW "W"
#ELSE
    #DEFINE AW "A"
#ENDIF
type
    INSTALLSTATE = Longint;
const
    INSTALLSTATE_INVALIDARG = -2;  // An invalid parameter was passed to the function.
    INSTALLSTATE_UNKNOWN = -1;     // The product is neither advertised or installed.
    INSTALLSTATE_ADVERTISED = 1;   // The product is advertised but not installed.
    INSTALLSTATE_ABSENT = 2;       // The product is installed for a different user.
    INSTALLSTATE_DEFAULT = 5;      // The product is installed for the current user.

    //DOWNLOADS FOR VISUAL C++ 2013
    VC_REDIST2013_URL = 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe';
    VC_REDIST2013_URL_x64 = 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe';

    //OPTIONS
    VC_2013_REDIST = '{13A4EE12-23EA-3371-91EE-EFB36DDFFF3E}'; //Microsoft.VS.VC_RuntimeMinimumVSU_x86,v12
    VC_2013_REDIST_x64 = '{A749D8E6-B613-3BE3-8F5F-045C84EBA29B}'; //Microsoft.VS.VC_RuntimeMinimumVSU_amd64,v12

    function MsiQueryProductState(szProduct: String): INSTALLSTATE;
    external 'MsiQueryProductState{#AW}@msi.dll stdcall';

function VCVersionInstalled(const ProductID: String): Boolean;
begin
    Result := MsiQueryProductState(ProductID) = INSTALLSTATE_DEFAULT;
end;

procedure vcredist2013();
var 
     target_x86_Only: Boolean;
     target_x64_Only: Boolean;
     target_x64x86_Either: Boolean;
begin
     //OPTION SETTINGS ONE TRUE ONLY
     target_x86_Only := True;
     target_x64_Only := False;
     target_x64x86_Either := False;
     //END OPTION SETTINGS


    //Will Install 32 bit only.
    if (target_x86_only = True) then begin
        if NOT VCVersionInstalled(VC_2013_REDIST) then
           AddProduct('vcredist_x86.exe',  
              CustomMessage('vcredist2013_lcid') + '/install /quiet /norestart',
              CustomMessage('vcredist2013_title'),
              CustomMessage('vcredist2013_size'),
              VC_REDIST2013_URL,
                false, false);
     end;      

     //Will attempt to install 64 bit only
     if (target_x64_Only) then begin
         if (IsX64) then begin
            if NOT VCVersionInstalled(VC_2013_REDIST_x64) then
               AddProduct('vcredist_x64.exe',  
                  CustomMessage('vcredist2013_lcid') + '/install /quiet /norestart',
                  CustomMessage('vcredist2013_title_x64'),
                  CustomMessage('vcredist2013_size_x64'),
                  VC_REDIST2013_URL_x64,
                    false, false);
          end else begin
             MsgBox('Sorry Cant install x64 application on x86 machine.', mbInformation, MB_OK); 
          end;
     end; 

     //Will attempt to install x64 and if it's not available it will install the x86 version
     if (target_x64x86_Either) then begin
         if (IsX64) then begin
            if NOT VCVersionInstalled(VC_2013_REDIST_x64) then
               AddProduct('vcredist_x64.exe',  
                  CustomMessage('vcredist2013_lcid') + '/install /quiet /norestart',
                  CustomMessage('vcredist2013_title_x64'),
                  CustomMessage('vcredist2013_size_x64'),
                  VC_REDIST2013_URL_x64,
                    false, false);
          end else begin
              if NOT VCVersionInstalled(VC_2013_REDIST) then
                 AddProduct('vcredist_x86.exe',  
                CustomMessage('vcredist2013_lcid') + '/install /quiet /norestart',
                CustomMessage('vcredist2013_title'),
                CustomMessage('vcredist2013_size'),
                VC_REDIST2013_URL,
                  false, false);
          end;
     end; 
end;

【问题讨论】:

  • 您确定您正在查看正确的注册表项吗? *VisualStudio\12.0\VC\VCRedist*。那是表明已安装 2013 的密钥吗?如果没有,它会每次都重新安装,因为你检查的版本是错误的。
  • VC Redist 2012 有人要求我提供此功能(SO 上的here,多次通过邮件发送)。但问题是这些产品代码没有官方列表,所以我把它放在了我的待办事项列表的底部。
  • 可能是这样。更重要的是,您链接的站点上的列表是 MSI 产品代码列表。我在我链接的评论附近的帖子中使用的代码。 MSI API 在这里应该是正确的方式,因此您只需选择您选择的产品代码,然后向 MsiQueryProductState 函数询问其状态。这个函数在后台的作用不应该是你感兴趣的 ;-)
  • 我没有在我的代码中使用 isxdl.dll 库。我只从 Windows API 库 msi.dll 导入一个函数,所以问题不会出现在我的检测代码中。请您尝试只运行检测部分而不运行下载器部分吗?
  • 一个hint for DRY 模式。

标签: visual-studio-2013 inno-setup


【解决方案1】:

@TLama 感谢您对此提供的所有帮助...

这是我的最终版本.....

// requires Windows 7 Service Pack 1, Windows 8, Windows 8.1, Windows Server 2003, Windows Server 2008 R2 SP1, Windows Server 2008 Service Pack 2, Windows Server 2012, Windows Server 2012 R2, Windows Vista Service Pack 2, Windows XP Service Pack 3
// requires Windows Installer 3.1 or later (??)
// requires Internet Explorer 5.01 or later (??)
// http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992
// Thank you (Martyn) https://allthingsconfigmgr.wordpress.com/2013/12/17/visual-c-redistributables-made-simple/
// http://stackoverflow.com/questions/27582762/inno-setup-for-visual-c-redistributable-package-for-visual-studio-2013
// http://stackoverflow.com/questions/11137424/how-to-make-vcredist-x86-reinstall-only-if-not-yet-installed

[CustomMessages]
vcredist2013_title=Visual C++ 2013 Redistribute (32bit)
vcredist2013_title_x64=Visual C++ 2013 Redistribute (64bit)

en.vcredist2013_size=6.2 MB
de.vcredist2013_size=6,2 MB

en.vcredist2013_size_x64=6.9 MB
de.vcredist2013_size_x64=6,9 MB

;http://www.microsoft.com/globaldev/reference/lcid-all.mspx
en.vcredist2013_lcid=''
de.vcredist2013_lcid='/lcid 1031 '

[Code]
#IFDEF UNICODE
    #DEFINE AW "W"
#ELSE
    #DEFINE AW "A"
#ENDIF
type
    INSTALLSTATE = Longint;
const
    INSTALLSTATE_INVALIDARG = -2;  // An invalid parameter was passed to the function.
    INSTALLSTATE_UNKNOWN = -1;     // The product is neither advertised or installed.
    INSTALLSTATE_ADVERTISED = 1;   // The product is advertised but not installed.
    INSTALLSTATE_ABSENT = 2;       // The product is installed for a different user.
    INSTALLSTATE_DEFAULT = 5;      // The product is installed for the current user.

    //DOWNLOADS FOR VISUAL C++ 2013
    VC_REDIST2013_URL = 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe';
    VC_REDIST2013_URL_x64 = 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe';

    //OPTIONS
    VC_2013_REDIST = '{13A4EE12-23EA-3371-91EE-EFB36DDFFF3E}'; //Microsoft.VS.VC_RuntimeMinimumVSU_x86,v12
    VC_2013_REDIST_x64 = '{A749D8E6-B613-3BE3-8F5F-045C84EBA29B}'; //Microsoft.VS.VC_RuntimeMinimumVSU_amd64,v12

    function MsiQueryProductState(szProduct: String): INSTALLSTATE;
    external 'MsiQueryProductState{#AW}@msi.dll stdcall';

function VCVersionInstalled(const ProductID: String): Boolean;
begin
    Result := MsiQueryProductState(ProductID) = INSTALLSTATE_DEFAULT;
end;

procedure vcredist2013();
var 
     target_x86_Only: Boolean;
     target_x64_Only: Boolean;
     target_x64x86_Either: Boolean;
begin
     //OPTION SETTINGS ONE TRUE ONLY
     target_x86_Only := True;
     target_x64_Only := False;
     target_x64x86_Either := False;
     //END OPTION SETTINGS


    //Will Install 32 bit only.
    if (target_x86_only = True) then begin
        if NOT VCVersionInstalled(VC_2013_REDIST) then
           AddProduct('vcredist_x86.exe',  
              CustomMessage('vcredist2013_lcid') + '/install /quiet /norestart',
              CustomMessage('vcredist2013_title'),
              CustomMessage('vcredist2013_size'),
              VC_REDIST2013_URL,
                false, false);
     end;      

     //Will attempt to install 64 bit only
     if (target_x64_Only) then begin
         if (IsX64) then begin
            if NOT VCVersionInstalled(VC_2013_REDIST_x64) then
               AddProduct('vcredist_x64.exe',  
                  CustomMessage('vcredist2013_lcid') + '/install /quiet /norestart',
                  CustomMessage('vcredist2013_title_x64'),
                  CustomMessage('vcredist2013_size_x64'),
                  VC_REDIST2013_URL_x64,
                    false, false);
          end else begin
             MsgBox('Sorry Cant install x64 application on x86 machine.', mbInformation, MB_OK); 
          end;
     end; 

     //Will attempt to install x64 and if it's not available it will install the x86 version
     if (target_x64x86_Either) then begin
         if (IsX64) then begin
            if NOT VCVersionInstalled(VC_2013_REDIST_x64) then
               AddProduct('vcredist_x64.exe',  
                  CustomMessage('vcredist2013_lcid') + '/install /quiet /norestart',
                  CustomMessage('vcredist2013_title_x64'),
                  CustomMessage('vcredist2013_size_x64'),
                  VC_REDIST2013_URL_x64,
                    false, false);
          end else begin
              if NOT VCVersionInstalled(VC_2013_REDIST) then
                 AddProduct('vcredist_x86.exe',  
                CustomMessage('vcredist2013_lcid') + '/install /quiet /norestart',
                CustomMessage('vcredist2013_title'),
                CustomMessage('vcredist2013_size'),
                VC_REDIST2013_URL,
                  false, false);
          end;
     end; 
end;

希望这对其他人有所帮助。

【讨论】:

  • Modular InnoSetup Dependency Installer (stfx) 的作者更新了他的收藏,以更正确地包含上面的代码 - codeproject.com/Articles/20868/… 在那里获取更新版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-07
  • 1970-01-01
  • 2014-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多