What is the reason for the error message “System cannot find the path specified”?

蓝咒 提交于 2019-12-03 05:51:54

There is not only 1 %SystemRoot%\System32 on Windows x64. There are 2 such directories.

The real %SystemRoot%\System32 directory is for 64-bit applications. This directory contains a 64-bit cmd.exe.

But there is also %SystemRoot%\SysWOW64 for 32-bit applications. This directory is used if a 32-bit application accesses %SystemRoot%\System32. It contains a 32-bit cmd.exe.

32-bit applications can access %SystemRoot%\System32 for 64-bit applications by using %SystemRoot%\Sysnative in path.

For more details see the Microsoft documentation about File System Redirector.

So I think you have created the subdirectory run in %SystemRoot%\System32 for 64-bit applications and run 32-bit cmd for which this directory does not exist as there is no subdirectory run in %SystemRoot%\SysWOW64 which is %SystemRoot%\System32 for 32-bit cmd.exe.

Or you have created the subdirectory run in %SystemRoot%\System32 for 32-bit applications and run 64-bit cmd for which this directory does not exist as there is no subdirectory run in %SystemRoot%\System32 because this subdirectory exists only in %SystemRoot%\SysWOW64.

You could use following at top of your batch file in case of subdirectory run is in %SystemRoot%\System32 for 64-bit applications:

@echo off
set "SystemPath=%SystemRoot%\System32"
if not "%ProgramFiles(x86)%"=="" (
    if exist %SystemRoot%\Sysnative\* set "SystemPath=%SystemRoot%\Sysnative"
)

Next you need to call every console application in System32\run directory with %SystemPath% in your batch file, for example %SystemPath%\run\YourApp.exe.

How it works?

On Windows x86 there is no environment variable ProgramFiles(x86) and therefore there is really only 1 %SystemRoot%\System32 as defined at top.

On Windows x64 there is the environment variable ProgramFiles(x86) with a value. On Windows x64 it is additionally checked if there are files in %SystemRoot%\Sysnative. In this case the batch file is executed with 32-bit cmd.exe and only in this case %SystemRoot%\Sysnative needs to be used at all. Otherwise %SystemRoot%\System32 can be used also on Windows x64 as when the batch file is started with 64-bit cmd.exe, this is the directory containing the 64-bit console applications (and your subdirectory run).

Note: %SystemRoot%\Sysnative is not a directory! It is not possible to cd to %SystemRoot%\Sysnative or use if exist %SystemRoot%\Sysnative

You just need to:

Step 1: Go home directory of C:\ with typing cd.. (2 times)

Step 2: It appears now C:\>

Step 3: Type dir Windows\System32\run

That's all, it shows complete files & folder details inside target folder.

Details: I used Windows\System32\com folder as example, you should type your own folder name etc. Windows\System32\run

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