Search code examples
inno-setuppascalscript

Inno Setup: How to rename system32 files in 64-bit OS


System32 and syswow64 folders are exist under C:\Windows in 64-bit OS.

I have a file called xyz.sys under System32\drivers folder. I tried to rename xyz.sys to xyz1.sys using below code:

if FileExists(ExpandConstant('{sys}\drivers\xyz.sys')) then
  RenameFile(ExpandConstant('{sys}\drivers\xyz.sys'), ExpandConstant('{sys}\drivers\xyz1.sys'));

But in 64-bit OS, innosetup is taking {sys}='Driveletter:\Windows\syswow64' as default one.

Even i tried below code to rename xyz.sys file under System32\drivers:

if FileExists(ExpandConstant('{win}\System32\drivers\xyz.sys')) then
  RenameFile(ExpandConstant('{win}\System32\drivers\xyz.sys'), ExpandConstant('{win}\System32\drivers\xyz1.sys'));

But above code also not working, can anyone suggest me how to rename system32 files in 64-bit OS.

Am using windows2008R2.


Solution

  • By default 32-bit applications (and installers for 32-bit apps) can only access the 32-bit system folder. You can use the 64bit flag on various entries to override this, if there is a specific 64-bit file you need to install for a 32-bit application, for example.

    You can do the same thing from [Code] by using the EnableFsRedirection support function. That help page shows an example of executing the 64-bit command prompt; you can similarly access the 64-bit {sys} from within that block. Don't forget to restore the previous state afterwards, as shown.

    Bear in mind however that renaming an installed driver file is generally not a good idea -- there will be catalog and INF files still pointing to its old name, and the system may get confused by this. It's better to properly uninstall the driver and reinstall the new one.