[英]Remove Trailing \ in subst Command
I have added a command to my Context Menu via the Registry in HKCR\\Drive\\shell\\MapLocalDriveHere\\command such that when I right click a drive. 我已经通过HKCR \\ Drive \\ shell \\ MapLocalDriveHere \\命令中的注册表向我的上下文菜单添加了一个命令,这样当我右键单击一个驱动器时。 I'd like it to give me the name of the drive that I have right-clicked as "C:" not "C:\\", as this causes problems with the command I'm trying to run.
我希望它能给我一个右键单击的驱动器名称“C:”而不是“C:\\”,因为这会导致我正在尝试运行的命令出现问题。
cmd /c subst %1 /D
This expands to: 这扩展到:
cmd /c subst C:\ /D
And the command fails (it expects subst C: /D
). 并且命令失败(它期望
subst C: /D
)。 How do I get the parameter without the trailing \\, or remove it? 如何在没有尾随\\的情况下获取参数,或者将其删除?
%~d1
and %~1
don't expand from the registry key, type REG_EXPAND_SZ. %~d1
和%~1
不从注册表项扩展,键入REG_EXPAND_SZ。
You can understand better what I'm trying to do by viewing the source of the project, located at https://github.com/Ehryk/ContextMenuTools (especially this file: https://github.com/Ehryk/ContextMenuTools/blob/master/Custom%20Installs/Map%20Local%20Drive%20Here/MapLocalDriveHere.inf ) 您可以通过查看位于https://github.com/Ehryk/ContextMenuTools的项目来源(尤其是此文件: https : //github.com/Ehryk/ContextMenuTools/blob)更好地了解我正在尝试做的事情。 /master/Custom%20Installs/Map%20Local%20Drive%20Here/MapLocalDriveHere.inf )
你进入一个带有%%~d
参数的for /f
循环带冒号的驱动器号:
FOR /f "delims=" %%a IN ("%~1") DO cmd /c subst %%~da /D
Well... Let's combine the best features of captcha's and npocmaka's answers. 好吧......让我们结合验证码和npocmaka的答案的最佳功能。 There is no need for an intermediate variable, nor is there a need for a FOR statement:
不需要中间变量,也不需要FOR语句:
cmd /c subst %~d1 /D
set "param=%~1"
set "param=%param:~0,-1%"
cmd /c subst %param% /D
For some reason, I had to switch to %V
instead of %1
to resolve this in the registry: 出于某种原因,我不得不切换到
%V
而不是%1
来在注册表中解决此问题:
cmd /c mapdrive.bat ""%V"" /D
HKCR,Drive\Shell\MapLocalDriveHere\command,,0x00020000,"cmd /c mapdrive.bat ""%V"" /D"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.