質問

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. 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.

cmd /c subst %1 /D

This expands to:

cmd /c subst C:\ /D

And the command fails (it expects 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.

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 )

役に立ちましたか?

解決 4

For some reason, I had to switch to %V instead of %1 to resolve this in the registry:

cmd /c mapdrive.bat ""%V"" /D

HKCR,Drive\Shell\MapLocalDriveHere\command,,0x00020000,"cmd /c mapdrive.bat ""%V"" /D"

他のヒント

You get in a for /f loop with the %%~d parameter the drive letter with a colon:

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. There is no need for an intermediate variable, nor is there a need for a FOR statement:

cmd /c subst %~d1 /D
set "param=%~1"
set "param=%param:~0,-1%"
cmd /c subst %param% /D
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top