visual c++ - InnoSetup 脚本安装 VC 可再发行组件并注册 VC OCX 导致"RegSrv32 failed with exit code 0x1"



我的InnoSetup脚本需要安装VC可重新发行版(vcredist_x86.exe),但也注册一个OCX依赖于redist包。我无法在regsrv32调用之前安装软件包,因此在处女系统上,它总是导致"regsrv32失败,退出代码为0x1"错误(我可以忽略并再次运行安装程序以正确注册OCX)。如何确保在注册之前安装了redist包?

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
[Setup]
AppName=MyApp
AppVerName=MyApp v1.0
DiskSpanning=no
AppPublisher=me
AppPublisherURL=http://www.example.com
AppSupportURL=http://www.example.com
AppUpdatesURL=http://www.example.com
DefaultDirName={pf}MyApp
UsePreviousAppDir=yes
DefaultGroupName=MyApp
OutputBaseFilename=Setup
OutputDir=.MyAppSetup
MinVersion=5.0
[Tasks]
Name: desktopicon; Description: Create a &desktop icon; GroupDescription: Additional icons:; MinVersion: 4,4
[Files]
;Source: "C:Program Files (x86)Microsoft Visual Studio 9.0VCredistx86Microsoft.VC90.CRTmsvcm90.dll"; DestDir: {app};
;Source: "C:Program Files (x86)Microsoft Visual Studio 9.0VCredistx86Microsoft.VC90.CRTmsvcp90.dll"; DestDir: {app};
;Source: "C:Program Files (x86)Microsoft Visual Studio 9.0VCredistx86Microsoft.VC90.CRTmsvcr90.dll"; DestDir: {app};
;Source: "C:Program Files (x86)Microsoft Visual Studio 9.0VCredistx86Microsoft.VC90.ATLatl90.dll"; DestDir: {app};
;Source: "C:Program Files (x86)Microsoft Visual Studio 9.0VCredistx86Microsoft.VC90.MFCmfc90.dll"; DestDir: {app};
;Source: "C:Program Files (x86)Microsoft Visual Studio 9.0VCredistx86Microsoft.VC90.MFCLOCMFC90DEU.dll"; DestDir: {app};
;Source: "C:Program Files (x86)Microsoft Visual Studio 9.0VCredistx86Microsoft.VC90.OPENMPvcomp90.dll"; DestDir: {app};      
Source: .SystemFilesvcredist_x86.exe; DestDir: {tmp}; Flags: deleteafterinstall;   
;-> [Run] !!
Source: .ReleaseMyApp.exe; DestDir: {app}; Flags: ignoreversion
Source: .ReleaseMyAppHelper.ocx; DestDir: {app}; Flags: regserver restartreplace  
[Icons]
Name: {group}EasyCash&Tax; Filename: {app}MyApp.exe
Name: {userdesktop}EasyCash&Tax; Filename: {app}MyApp.exe; MinVersion: 4,4; Tasks: desktopicon
[Run]
Filename: {tmp}vcredist_x86.exe; Parameters: "/q:a /c:""VCREDI~3.EXE /q:a /c:""""msiexec /i vcredist.msi /qn"""" """; Flags: runhidden shellexec waituntilterminated;
Filename: {app}MyApp.exe; Description: Launch MyApp; Flags: nowait postinstall skipifsilent

为方便起见,以下是来自pastebin TLama的代码:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}My Program
[Files]
Source: ".SystemFilesvcredist_x86.exe"; Flags: dontcopy
[Code]
function IsRuntimeInstalled: Boolean;
begin
  Result := False;
  // here will be a statement that will check whether the runtime is installed
  // and return True if so; see e.g. http://stackoverflow.com/q/11137424/960757
end;
function PrepareToInstall(var NeedsRestart: Boolean): string;
var
  ExitCode: Integer;
begin
  // if the runtime is not already installed
  if not IsRuntimeInstalled then
  begin
    // extract the redist to the temporary folder
    ExtractTemporaryFile('vcredist_x86.exe');
    // run the redist from the temp folder; if that fails, return from this handler the error text
    if not Exec(ExpandConstant('{tmp}vcredist_x86.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ExitCode) then
    begin
      // return the error text
      Result := 'Setup failed to install VC++ runtime. Exit code: ' + IntToStr(ExitCode);
      // exit this function; this makes sense only if there are further prerequisites to install; in this
      // particular example it does nothing because the function exits anyway, so it is pointless here
      Exit;
    end;
  end;
end;

最新更新