Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要制作一个批处理文件来检测它所在的驱动器和目录。当我正常运行该文件时,它已经在正确的目录/驱动器中。但是当它以管理员身份运行时,它会在 system32 中启动。是否有进入批处理来源的目录或驱动器的命令?
你可以使用
Pushd "%~dp0"
这会将当前目录更改为批处理文件的路径。 引用该参数可以防止路径名中的特殊字符,如“C:\Documents & Settings”
一个解决方法是\在路径之前使用给出绝对路径。
\
所以,如果你需要运行一个文件c:\temp\xyz.exe,即使你c:\winodws\system32仍然在目录中,当你运行时cd \temp\xyz.exe,文件仍然会正常运行
c:\temp\xyz.exe
c:\winodws\system32
cd \temp\xyz.exe