windows - 如何创建名称中带有正斜杠的注册表项

标签 windows powershell registry

我需要创建以下注册表项 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 : 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

并且使用 PowerShell 反引号 ` 转义字符也无济于事。

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

如有建议,我们将不胜感激。谢谢

最佳答案

这是对 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) 创建 key 。

关于windows - 如何创建名称中带有正斜杠的注册表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18218835/

相关文章:

windows - starcluster easy_install windows

python-3.x - 有没有办法为Windows安装cython-bbox?

C 并行线程与并行进程

powershell - Powershell脚本可列出多个服务器上的大文件

Powershell 在单击事件上挂起

powershell - 在 PowerShell 7.2 中更改详细颜色

windows - InnoSetup - 为默认子项添加值?

c - RegQueryValue 失败但 RegQueryValueEx 返回一个值

Powershell - 从注册表项转换十六进制

c# - 使用 webkitdotnet 进行跨域调用