【问题标题】:Wrong behavior of IF EXIST on a file in C:\Windows\System32 in Windows batch (Inno Setup)IF EXIST 在 Windows 批处理中 C:\Windows\System32 中的文件的错误行为(Inno Setup)
【发布时间】:2016-04-25 01:15:51
【问题描述】:

我正在尝试通过 Inno Setup 使用批处理脚本来复制一个 Windows .dll 文件。

显然,即使C:\Windows\System32 中没有msvcr120.dll 文件(我可以确认)我也只能看到“文件存在”。 当然,我也试过把下面的双引号去掉。

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
)   

我手动检查过

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

你能告诉我有什么问题吗?

如何在 Inno Setup 中运行批处理

[Run]

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

其他结果

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).

更新

Windows 7 64bit 并且在 C:\Windows\SysWOW64 中有一个 msvcr120.dll。 但我正在尝试将文件从我的源目录复制到 C:\Windows\System32。

【问题讨论】:

  • 也许msvcr120.dll 被隐藏了?试试dir /A:HS C:\Windows\System32\msvcr120.dll;或者有一个具有该名称的目录 - 将 /A:HS 替换为 /A:D 以进行测试...
  • 更新问题。我没有看到文件。实际上,有这个文件,但为了我的测试,我将原来的 msvcr120.dll 重命名为 msvcr120_backup.dll。我的目的是在文件不存在时复制它。
  • 也许也可以试试dir /A:L C:\Windows\System32\msvcr120.dlldir /S C:\Windows\msvcr120.*;或输入where msvcr120.dll...
  • 好的,所以问题正如我在回答中所描述的那样。你试过64bit 标志吗?
  • 等等,天才。我正在根据您的建议进行测试...

标签: batch-file inno-setup


【解决方案1】:

该文件可能存在于C:\Windows\SysWOW64

Inno Setup 是一个 32 位应用程序。所以默认情况下,要运行一个批处理文件,它会执行 32 位的cmd.exe

32位cmd.exe,查询时C:\Windows\System32gets redirectedC:\Windows\SysWOW64

了解issues with 32-bit vs. 64-bit installations


如果您使用[Run] 部分中的条目运行批处理文件,请使用64bit flag 强制执行64 位cmd.exe

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

虽然如果它是一个 32 位 DLL,您实际上希望它在 C:\Windows\SysWOW64 中。

【讨论】:

  • 完美!!!!你是对的。它被重定向了。我需要复制文件的 64 位版本。现在,我的批处理文件检测到它不存在并成功复制!!非常感谢!!
猜你喜欢
  • 1970-01-01
  • 2011-03-16
  • 1970-01-01
  • 2017-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-10
相关资源
最近更新 更多