Creating a registry key with path components via PowerShell

前端 未结 1 1114
我寻月下人不归
我寻月下人不归 2021-01-18 06:39

For a legacy application, I need to create a registry key with a name in the format c:/foo/bar/baz. (Note: forward slashes, not backslashes.) To be clear: tha

相关标签:
1条回答
  • 2021-01-18 07:16

    You need to do two things. First you need to get a writable RegistryKey object, otherwise you can't modify anything anyway. Second, use the CreateSubKey method on the RegistryKey object directly.

    $writable = $true
    $key = (get-item HKLM:\).OpenSubKey("SOFTWARE", $writable).CreateSubKey("C:/test")
    $key.SetValue("Item 1", "Value 1")
    

    After you create the key you use the resulting object to add values to it.

    0 讨论(0)
提交回复
热议问题