Wrong behavior of IF EXIST on a file in C:\\Window

2019-01-26 20:15发布

问题:

I'm trying to copy one Windows .dll file by using a batch script through Inno Setup.

Apparently, even though there is no msvcr120.dll file in C:\Windows\System32 (I can confirm) I can only see "file exists". Of course, I also tried to remove double quotation below.

if exist "C:\Windows\System32\msvcr120.dll" (
    rem file exists
    echo  "file exists"
    pause
) else (
    rem file doesn't exist
    copy %1\Utilities\msvcr120.dll  C:\Windows\System32\msvcr120.dll
    echo  "file doesn't exist"
    pause
)   

I checked it manually

C:\Users\changwon>dir /A:HS C:\Windows\System32\msvcr120.dll
 Volume in drive C has no label.
 Volume Serial Number is 4A80-BDED

 Directory of C:\Windows\System32

File Not Found

Can you tell me what is wrong?

How to run a batch in Inno Setup

[Run]

Filename: "{app}\bin\Icacls\cacls.bat"; Parameters: """{app}"""
Filename: "{app}\Install\psql_init.bat"; Parameters: """{app}"""

Other results

C:\Users\changwon>dir /A:L C:\Windows\System32\msvcr120.dll
 Directory of C:\Windows\System32

File Not Found

C:\Users\changwon>where msvcr120.dll
INFO: Could not find files for the given pattern(s).

UPDATE

Windows 7 64bit and there is a msvcr120.dll in C:\Windows\SysWOW64 instead. But I'm trying to copy the file from my source dir to C:\Windows\System32.

回答1:

The file probably exists in the C:\Windows\SysWOW64.

Inno Setup is a 32-bit application. So by default, to run a batch file, it executes the 32-bit cmd.exe.

The 32-bit cmd.exe, when querying the C:\Windows\System32, gets redirected to the C:\Windows\SysWOW64.

Read about issues with 32-bit vs. 64-bit installations.


If you are running the batch file using an entry in the [Run] section, use the 64bit flag to force execution of the 64-bit cmd.exe:

[Run]
Filename: "{app}\bin\Icacls\cacls.bat"; Parameters: """{app}"""; Flags: 64bit
Filename: "{app}\Install\psql_init.bat"; Parameters: """{app}"""; Flags: 64bit

Though if it is a 32-bit DLL, you actually want it in the C:\Windows\SysWOW64.