Windows x64 上不仅 有1 %SystemRoot%\System32。有2 个这样的目录。
真正的%SystemRoot%\System32目录用于 64 位应用程序。该目录包含一个 64 位 cmd.exe.
但也%SystemRoot%\SysWOW64适用于 32 位应用程序。如果 32 位应用程序访问%SystemRoot%\System32. 它包含一个 32 位的cmd.exe.
32 位应用程序可以通过使用路径%SystemRoot%\System32中的别名访问 64 位应用程序。%SystemRoot%\Sysnative
有关更多详细信息,请参阅有关文件系统重定向器的 Microsoft 文档。
因此,子目录run是%SystemRoot%\System32为 64 位应用程序创建的,并且cmd运行 32 位,但该目录不存在,因为没有用于 32 位的子目录,或者子目录run是为 32 位应用程序和 64 位应用程序创建的运行该目录不存在的-bit ,因为没有子目录,因为该子目录仅存在于.%SystemRoot%\SysWOW64%SystemRoot%\System32cmd.exe run%SystemRoot%\System32cmdrun%SystemRoot%\System32%SystemRoot%\SysWOW64
run如果子目录位于%SystemRoot%\System3264 位应用程序中,则可以在批处理文件顶部使用以下代码:
@echo off
set "SystemPath=%SystemRoot%\System32"
if not "%ProgramFiles(x86)%" == "" if exist %SystemRoot%\Sysnative\* set "SystemPath=%SystemRoot%\Sysnative"
目录中的每个控制台应用程序都System32\run必须%SystemPath%在批处理文件中执行,例如%SystemPath%\run\YourApp.exe.
这个怎么运作?
在 Windows x86 上没有环境变量ProgramFiles(x86),因此实际上只有%SystemRoot%\System32顶部定义的一个。
但是在 Windows x64 上定义了具有值的环境变量ProgramFiles(x86) 。因此,如果%SystemRoot%\Sysnative. 在这种情况下,批处理文件当前由 32 位处理cmd.exe,只有在这种情况下%SystemRoot%\Sysnative才需要使用。否则%SystemRoot%\System32也可以在 Windows x64 上使用,因为当批处理文件由 64-bit 处理时cmd.exe,这是包含 64-bit 控制台应用程序的目录(和子目录run)。
注意:%SystemRoot%\Sysnative不是目录!不可能cd使用%SystemRoot%\Sysnativeor 。if exist %SystemRoot%\Sysnative_ if exist %SystemRoot%\Sysnative\它是仅存在于 32 位可执行文件的特殊别名,因此有必要通过 usingif exist %SystemRoot%\Sysnative\cmd.exe或更通用的if exist %SystemRoot%\Sysnative\*.