Inno setup Inno安装程序无法在x64上找到并执行ie4uinit.exe

Inno setup Inno安装程序无法在x64上找到并执行ie4uinit.exe,inno-setup,pascalscript,Inno Setup,Pascalscript,我正在尝试使用众所周知且有文档记录的方法刷新Windows图标缓存,该方法调用ie4uinit.exe-ClearIconCache,用于Windows 10及以上版本的Windows 10和ie4uinit.exe-Show: [Run] Filename: "{sys}\ie4uinit.exe"; Parameters: "-ClearIconCache"; StatusMsg: "Rebuilding Windows icon cache..."; Flags: runhidden; C

我正在尝试使用众所周知且有文档记录的方法刷新Windows图标缓存,该方法调用
ie4uinit.exe-ClearIconCache
,用于Windows 10及以上版本的Windows 10和
ie4uinit.exe-Show

[Run]
Filename: "{sys}\ie4uinit.exe"; Parameters: "-ClearIconCache"; StatusMsg: "Rebuilding Windows icon cache..."; Flags: runhidden; Check: not IsWindows10AndAbove
Filename: "{sys}\ie4uinit.exe"; Parameters: "-Show"; StatusMsg: "Rebuilding Windows icon cache..."; Flags: runhidden; Check: IsWindows10AndAbove
在资源管理器中或在命令提示符下运行时,这两个命令都能正常工作。在x86系统上运行时,它们在Inno设置中也能正常工作。但是,在x64系统上,会产生以下错误:

使用
{sys}
常量的文件路径正确解析,并且文件存在,可以在资源管理器和命令提示符下的目录列表中看到:

通过命令提示符运行的上述代码的以下变体也会以大致相同的方式失败,尽管它是静默的,并且仅由安装日志中的退出代码1指示

[Run]
Filename: "{cmd}"; Parameters: "/c {sys}\ie4uinit.exe -ClearIconCache"; StatusMsg: "Rebuilding Windows icon cache..."; Flags: runhidden; Check: not IsWindows10AndAbove
Filename: "{cmd}"; Parameters: "/c {sys}\ie4uinit.exe -Show"; StatusMsg: "Rebuilding Windows icon cache..."; Flags: runhidden; Check: IsWindows10AndAbove
我已经读过了,其中也提到这是Inno设置中的一个问题(在底部),并尝试了复制文件并从其他地方运行它的解决方法。但是,尝试使用
FileCopy
功能将文件复制到另一个位置时,也未能在
C:\Windows\System32
中找到该文件。我还尝试使用
Exec
函数在
[code]
部分运行相同的命令,但在
C:\Windows\System32
中也找不到它

我考虑过制作一个文件副本并将其安装到temp目录以从那里运行它,但该文件在每个Windows版本上都是不同的版本,因此这并不是一个切实可行的解决方案,特别是作为一个系统文件,它在将来也可能会更改

上述问题的公认答案似乎是为“任何CPU”而不是“x86”构建可执行文件。但是,我不确定这是否可以在Inno安装程序中完成,以及这样做是否会对安装程序的行为产生任何不可预见的副作用


在Inno安装程序中有没有办法解决或解决这个问题?

我终于找到了答案。Inno安装程序找不到该文件,相当令人困惑的是,尽管它显示它正在
C:\Windows\System32
中查找,但Windows文件重定向实际上是在静默状态下导致它在
C:\Windows\SysWOW64
中查找,其中
ie4uinit.exe
不存在。因此,解决方案是在
[code]
部分使用
[Run]
部分安装前
和安装后
指令临时禁用文件重定向,然后使用
启用fsredirection
功能,在此之后,Inno安装程序现在可以查看并访问实际的
C:\Windows\System32
目录,将文件复制到临时目录并从那里运行,然后将文件重定向恢复到以前的状态:

[Run]
Filename: "{tmp}\Config Tools\ie4uinit.exe"; Parameters: "-ClearIconCache"; StatusMsg: "Refreshing Windows icon cache..."; Flags: runhidden; Check: not IsWindows10AndAbove; BeforeInstall: StartRefreshIconCache; AfterInstall: FinishRefreshIconCache
Filename: "{tmp}\Config Tools\ie4uinit.exe"; Parameters: "-Show"; StatusMsg: "Refreshing Windows icon cache..."; Flags: runhidden; Check: IsWindows10AndAbove; BeforeInstall: StartRefreshIconCache; AfterInstall: FinishRefreshIconCache

[Code]
//Start refresh or rebuild of the Windows icon cache
procedure StartRefreshIconCache();
var
  OriginalFileRedirectionState: Boolean;
begin
  if not IsWin64 then
    begin
      if FileCopy(ExpandConstant('{sys}\ie4uinit.exe'), ExpandConstant('{tmp}\Config Tools\ie4uinit.exe'), False) then
        begin
          Log(ExpandConstant('Copied {sys}\ie4uinit.exe to {tmp}\Config Tools\ie4uinit.exe'));
        end;
    end
  else if IsWin64 then
    begin
      //Store Windows file redirection's original state and temporarily disable to allow access to the System32 directory on x64 to allow copy of ie4uinit.exe
      OriginalFileRedirectionState := EnableFsRedirection(False); 
      Log('File redirection temporarily disabled for x64 compatibility.');
      try
        if FileCopy(ExpandConstant('{sys}\ie4uinit.exe'), ExpandConstant('{tmp}\Config Tools\ie4uinit.exe'), False) then
          begin
            Log(ExpandConstant('Copied {sys}\ie4uinit.exe to {tmp}\Config Tools\ie4uinit.exe'));
          end;
      finally
        //Restore file redirection's original state
        EnableFsRedirection(OriginalFileRedirectionState);
        Log('File redirection restored to it''s original state.');
      end;
    end;
end;

//Finish refresh or rebuild of the Windows icon cache
procedure FinishRefreshIconCache();
begin
  if DeleteFile(ExpandConstant('{tmp}\Config Tools\ie4uinit.exe')) then
    begin
      Log(ExpandConstant('Deleted {tmp}\Config Tools\ie4uinit.exe'));    
    end;
end;

一个更简单、更好的解决方案(感谢Martin提供的链接)是为x64使用两个重复的
[Run]
条目,其中包含
Check:IsWin64
标志:64位
,并将
Check:not IsWin64
添加到原始行:

[Run]
Filename: "{sys}\ie4uinit.exe"; Parameters: "-ClearIconCache"; StatusMsg: "Refreshing Windows icon cache..."; Flags: runhidden; Check: not IsWindows10AndAbove and not IsWin64
Filename: "{sys}\ie4uinit.exe"; Parameters: "-Show"; StatusMsg: "Refreshing Windows icon cache..."; Flags: runhidden; Check: IsWindows10AndAbove and not IsWin64
Filename: "{sys}\ie4uinit.exe"; Parameters: "-ClearIconCache"; StatusMsg: "Refreshing Windows icon cache..."; Flags: runhidden 64bit; Check: not IsWindows10AndAbove and IsWin64
Filename: "{sys}\ie4uinit.exe"; Parameters: "-Show"; StatusMsg: "Refreshing Windows icon cache..."; Flags: runhidden 64bit; Check: IsWindows10AndAbove and IsWin64
另见