如何创建名称中带有正斜杠的注册表项 [英] How to create a registry entry with a forward slash in the name
问题描述
我需要创建以下注册表项HKLM:\software\bmc software\control-m/agent
但是由于代理"之前的正斜杠而出现问题
我创建一个没有正斜杠的条目没有问题例如:
PS C:\powershell>new-item -path 'HKLM:\software\bmc software\control-mXXXagent'
但是使用正斜杠创建失败.
PS C:\powershell>new-item -path 'HKLM:\software\bmc software\control-m/agent'
<块引用>
New-Item : 指定路径的注册表项不存在.在行:1 字符:10+ 新项目 <<<<-path 'HKLM:\software\bmc software\control-m/agent'+ CategoryInfo : InvalidArgument: (HKEY_LOCAL_MACH...tware\control-m:String) [New-Item], ArgumentException+ FullQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.NewItemCommand
并且使用 PowerShell backtic ` 转义字符也无济于事.
PS C:\powershell>new-item -path 'HKLM:\software\bmc software\control-m`/agent'
<块引用>
New-Item : 指定路径的注册表项不存在.在行:1 字符:10+ 新项目 <<<<-path 'HKLM:\software\bmc software\control-m/agent'+ CategoryInfo : InvalidArgument: (HKEY_LOCAL_MACH...ware\control-m
:String) [New-Item], ArgumentException+ FullQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.NewItemCommand
我们将不胜感激.谢谢
这是对 Ansgar 指出的帖子的轻微修改:
new-item -path 'HKLM:\software\bmc software'$key = (get-item HKLM:\).OpenSubKey("SOFTWARE\bmc software", $true)$key.CreateSubKey('control-m/agent')$key.Close()
这会使用实际的 /
字符 (0x2F) 创建密钥.
I need to create the following registry entry
HKLM:\software\bmc software\control-m/agent
but am having a problem due to the forward slash before "agent"
I have no problem creating an entry that doesn't have the forward slash For example:
PS C:\powershell> new-item -path 'HKLM:\software\bmc software\control-mXXXagent'
But creating with the forward slash fails.
PS C:\powershell> new-item -path 'HKLM:\software\bmc software\control-m/agent'
New-Item : The registry key at the specified path does not exist. At line:1 char:10 + new-item <<<< -path 'HKLM:\software\bmc software\control-m/agent' + CategoryInfo : InvalidArgument: (HKEY_LOCAL_MACH...tware\control-m:String) [New-Item], ArgumentExceptio n + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.NewItemCommand
And using the PowerShell backtic ` escape character doesn't help either.
PS C:\powershell> new-item -path 'HKLM:\software\bmc software\control-m`/agent'
New-Item : The registry key at the specified path does not exist. At line:1 char:10 + new-item <<<< -path 'HKLM:\software\bmc software\control-m
/agent' + CategoryInfo : InvalidArgument: (HKEY_LOCAL_MACH...ware\control-m
:String) [New-Item], ArgumentExceptio n + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.NewItemCommand
And advice would be appreciated. Thanks
This is a slight modification of the post that Ansgar pointed to:
new-item -path 'HKLM:\software\bmc software'
$key = (get-item HKLM:\).OpenSubKey("SOFTWARE\bmc software", $true)
$key.CreateSubKey('control-m/agent')
$key.Close()
This creates the key using the actual /
char (0x2F).
这篇关于如何创建名称中带有正斜杠的注册表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!