powershell - 递归复制注册表子树,其中某些子项名称包含斜杠

标签 powershell registry

我在使用 PowerShell 复制注册表子树时遇到问题,因为某些键包含斜杠(例如 HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\Languages\Language Services\C/C++ )

PS > Copy-Item -recurse HKCU:\Software\Microsoft\VisualStudio\11.0\Languages HKCU:\ZZZ

Copy-Item : The registry key at the specified path does not exist.
At line:1 char:1
+ Copy-Item -recurse HKCU:\Software\Microsoft\VisualStudio\11.0\Languages HKCU:\So ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (HKEY_CURRENT_US...odeExpansions\C:String) [Copy-Item], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.CopyItemCommand

Copy-Item : The registry key at the specified path does not exist.
At line:1 char:1
+ Copy-Item -recurse HKCU:\Software\Microsoft\VisualStudio\11.0\Languages HKCU:\So ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (HKEY_CURRENT_US...uage Services\C:String) [Copy-Item], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.CopyItemCommand

如何递归复制此类子树?

最佳答案

这是 Powershell 中的一个已知错误 - 它无法处理注册表路径中的正斜杠(适用于 get-childitem,因此我希望它也会影响 copy-item重命名项目移动项目等)。

https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=238838&SiteID=99

并且在最新的 powershell (v4.0) 中仍然存在。

但是,您可以使用 powershell 运行 Reg DOS 命令: http://technet.microsoft.com/en-us/library/cc742057.aspx

reg.exe copy HKCU:\Software\Microsoft\VisualStudio\11.0\Languages HKCU:\ZZZ /s

关于powershell - 递归复制注册表子树,其中某些子项名称包含斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21223283/

相关文章:

PowerShell 命令,-r 和-p 是什么意思? cp -r 和 cp -recurse 有什么区别

regex - PowerShell正则表达式在换行符附近不匹配

powershell - 有什么方法可以引用管道中的前一个对象吗?

c# - 我无法访问注册表条目中的某些子项

powershell - 测试Outlook是否在后台运行或可见

c# - CreateProcessWithTokenW winapi 返回 false 但没有原因

c# - 设置程序必须在启动时从安装程序运行

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

windows - 在 Inno Setup 中创建 REG_NONE 注册表值

c++ - 函数调用 CRegKey::QueryStringValue 出错