将已安装的文件 (.reg) 传递给 Inno Setup 中的程序 (regedit) 失败并显示 "Cannot import ... Error opening the file"

Passing an installed file (.reg) to program (regedit) in Inno Setup fails with "Cannot import ... Error opening the file"

我想在安装后导入一个reg文件。这是我的代码:

procedure CurStepChanged(CurStep: TSetupStep);
Var
    ResultCode: Integer;
begin
    if CurStep = ssPostInstall then begin
        Exec('{win}\regedit.exe', '{app}\MyReg.reg', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
    end;
end;

我也试过这个:

[Run]
Filename "{win}\regedit.exe"; Parameters: "{app}\MyReg.reg";

两者都失败了:

Cannot import MyReg.reg: Error opening the file. There may be a disk or file system error.

我尝试手动导入 reg 文件 (cmd.exe)

C:\Windows\regedit.exe MyReg.reg

如果您要安装到 Program Files,则 {app} 包含空格。

您应该始终将路径用双引号括起来,以允许带有空格的路径。

Exec('{win}\regedit.exe', '"{app}\MyReg.reg"', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);

同样:

[Run]
Filename "{win}\regedit.exe"; Parameters: """{app}\MyReg.reg""";