如何使用Inno Setup处理.msi文件?

时间:2012-02-16 15:01:06

标签: installer inno-setup

我在Inno Setup中有以下代码。

但是如何将这个类似的功能应用于.msi文件?

msiexec /I "\package\file.msi" /qb?怎么样?

procedure AfterMyProgInstall(S: String);
var
  ErrorCode: Integer;
begin
  {MsgBox('Please wait the libraries are getting installed, ' +
          'without the libraries it wont work.', mbInformation, MB_OK);}
  ExtractTemporaryFile(S);
  {SW_SHOW, SW_SHOWNORMAL, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, SW_SHOWMINNOACTIVE, SW_HIDE}
  ShellExec('', ExpandConstant('{app}\package\' + S), '', '', SW_SHOWNORMAL,
            ewWaitUntilTerminated, ErrorCode);
end;

4 个答案:

答案 0 :(得分:18)

试试这个:

ShellExec('', 'msiexec.exe',
  ExpandConstant('/I "{tmp}\package\file.msi" /qb'),
  '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);

或者:

[Files]
Source: file.msi; DestDir: {tmp}; Flags: deleteafterinstall;

[Run]
Filename: "msiexec.exe"; Parameters: "/i ""{tmp}\file.msi"" /qb"; WorkingDir: {tmp};

答案 1 :(得分:5)

以@kobik给出的答案为基础。我必须在文件名中包含'.exe'。 像这样:

if not ShellExec('', 'msiexec.exe', ExpandConstant('{tmp}\package\file.msi'),
  '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode)
then
  MsgBox('Msi installer failed to run!' + #13#10 + ' ' +
    SysErrorMessage(ErrorCode), mbError, MB_OK);

答案 2 :(得分:4)

注意:我在Windows 7上使用Inno Setup 5.5.3,而且这段代码 用于运行部分中的Inno Setup脚本。使用此代码即可 运行msi文件没有任何问题。这是代码:

[Run]
Filename: `{src}\PhysX.msi;` Description: Nvidia PhysX; Verb: open; Flags: shellexec postinstall waituntilterminated runascurrentuser skipifsilent

答案 3 :(得分:0)

尽管kobik在“运行”部分中选择使用“ msiexec.exe / i”的选项通常可行,但我们仍然面临着管理员权限降级的问题:

[Run]
Filename: "msiexec.exe"; Parameters: "/i ""{tmp}\file.msi"" /qb"; WorkingDir: {tmp};

以这种方式运行msiexec.exe / i file.msi时,它将请求具有UAC的管理员权限(正如预期的那样,在我们的情况下确实是必需的)。但是,在此安装部分中间的某个位置,当“ file.msi”试图启动Windows服务时,它似乎已降级并且没有足够的特权来启动Windows服务。 但是,当它通过shellexec启动时,它没有问题就可以了。这就是它的工作方式:

[Run]
Filename: "{tmp}\file.msi"; Flags: skipifsilent shellexec waituntilterminated hidewizard;