繁体   English   中英

批处理脚本-是否与管理员不同

[英]Batch Script - different when admin or not

我一直在尝试使用脚本复制文件,并且有以下代码。 运行时它将按预期显示:C:\\ Users \\ Nico \\ Desktop \\ Stopthe.scr

如果我以管理员身份运行它(它需要正常工作),它将显示不同的路径:C:\\ Windows \\ System32 \\ Stopthe.scr

我正在测试的脚本是在桌面上。

:: don't output the commands that are running to screen
echo OFF
:: label for a goto statement - although not required atm
:start
:: clears the screen
cls
:: variable - path to where script is located
set herePath=%cd%\Stopthe.scr
:: %cd% returns the current directory of where the script is.

echo  %herePath%
echo.

pause

我想找到路径,并且在正常运行时它会返回正确的路径,但是当以管理员身份运行时,它不会将路径返回到脚本(但可能是cmd.exe所在的位置)。

我理解%cd%返回脚本所在的当前目录,这就是我想要的。

以管理员身份运行批处理脚本始终会将工作目录(即%CD% )默认为C:\\Windows\\System32

脚本所在的路径是(包括反斜杠) %~dp0 ,因此可以使用

set "herePath=%~dp0Stopthe.scr"

资源: 命令行参数(参数)相对于批处理脚本的部件链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM