Inno Setup unable to find and execute ie4uinit.exe on x64 [duplicate]

寵の児 提交于 2019-12-04 18:22:21

A far simpler and better solution (thanks for the links Martin) is to have two duplicated [Run] entries for x64 with Check: IsWin64 and Flags: 64bit and to add Check: not IsWin64 to the original lines:

[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

I finally figured this out. Inno Setup cannot find the file as, rather confusingly, despite it displaying that it is looking in C:\Windows\System32, Windows file redirection is actually silently causing it to look in C:\Windows\SysWOW64, where ie4uinit.exe does not exist. The solution, therefore, is to temporarily disable file redirection in the [Code] section, using the [Run] section BeforeInstall and AfterInstall directives, followed by the EnableFsRedirection function, after which Inno Setup can now see and access the actual C:\Windows\System32 directory, copy the file to the temp directory and run it from there, before restoring file redirection to it's previous state:

[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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!