Powershell 逃逸文字路径

Powershell 逃逸文字路径,powershell,escaping,registry,Powershell,Escaping,Registry,我已通过设置以下内容将PowerShell添加到关联菜单: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\Powershell\command] @="powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'" 这很好用,除了一个我非常出色地命名为Ash'sdocs的文件夹。它失败于: The string is missing

我已通过设置以下内容将PowerShell添加到关联菜单:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Powershell\command]
@="powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
这很好用,除了一个我非常出色地命名为
Ash'sdocs
的文件夹。它失败于:

The string is missing the terminator: '. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString 字符串缺少终止符:'。 +CategoryInfo:ParserError:(:)[],ParentContainerErrorRecordException +FullyQualifiedErrorId:TerminatorExpectedAtEndOfString 从文档中:

指定位置的路径。LiteralPath参数的值的使用与键入的值完全相同。没有字符被解释为通配符。如果路径包含转义字符,请用单引号将其括起来。单引号告诉PowerShell不要将任何字符解释为转义序列


我是否可以选择使用
-Path
,希望我的目录名称中没有可能的通配符?或者可以在
%V
中转义单引号吗?

将路径放在双引号而不是单引号中。双引号不能出现在路径中。但是,双引号必须转义两次:对于.reg文件和PowerShell调用

Windows注册表编辑器5.00版
[HKEY\U CLASSES\U ROOT\Directory\shell\Powershell\command]
@=“powershell.exe-NoExit-命令集位置-LiteralPath\\\\%V\\\\”

'%V'
->
\%V\“
似乎不起作用-相同的错误。还尝试了
此处字符串
@“%V”@
,但没有luck@Ash我在发帖前测试过这个,所以我严重怀疑除非你做错了什么,否则它不会起作用。是的,用户错误-我测试的是
[HKEY\U CLASSES\U ROOT\Directory\Background\shell\Powershell\command]
而不是
[HKEY\U CLASSES\U ROOT\Directory\shell\Powershell\command]
谢谢!