Registry and special characters

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 1 year, 10 months ago.

  • Author
    Posts
  • #22642
    Profile photo of Troy Oosterwijk
    Troy Oosterwijk
    Participant

    Hi all,

    Me again with yet another question.

    I'm trying to create a new registry item in the [b]HKCR:\*\shell\ [/b]environment.
    Sadly though, I can't get Powershell to accept the wildcard character as a normal character.
    I've tried using the backtick and other escape characters, but it just doesn't seem to work.

    What doesn't work:

    New-Item -Path 'HKCR:\*\shell\takeownership\' -Name test –Force

    What does work:

    Set-Location -LiteralPath 'HKCR:\*\shell'
    New-Item -Name 'takeownership'

    I really would like to get the first one working, because it's part of a function I created for creating registry keys.
    If anyone has a solution to this problem, please let me know.

    Thanks in advance & regards,

    T.O.

  • #22643
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Normally you can escape those wildcard-supporting paths by putting the special characters in square brackets, but in my testing, that didn't seem to work. Maybe New-Item needs a -LiteralPath parameter.

    In the meantime, you might just need to work around this. If you want to use the registry provider and New-Item, you could split the path and use Set-Location -LiteralPath, or maybe you could resort to calling the .NET methods directly. Something like this:

    (Get-Item HKCR:\).CreateSubKey('*\shell\takeownership\test')
    

You must be logged in to reply to this topic.