Add registry key with forward slash

//Add registry key with forward slash
Add registry key with forward slash 2016-01-26T00:15:34+00:00

The Toolkit Forums General Add registry key with forward slash

  • Author
    Posts
  • Baatch
    Participant
    Post count: 8
    #1038 |

    Hi,

    I’m having problem adding a registry key with a forward slash:

    $HKCURegistrySettings = {
    Set-RegistryKey -Key ‘HKCU\Software\X\https://google.com/’ -SID $UserProfile.SID
    }

    Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings.ToString

    I’m only getting HKCU\SOFTWARE\X\HTTPS:\google.com and not HKCU\SOFTWARE\X\HTTPS:\\google.com

    I have searched and tried many things but there seems not to be a soluiton. Please help.

  • Muhammad Mashwani
    Keymaster
    Post count: 118

    PowerShell interprets a forward slash as a path separator. You will need to do something like this to write a forward slash to the registry:

    $HKCURegistrySettings = {
    Set-RegistryKey -Key “HKCU\Software\X\https:$([char]0x2F)$([char]0x2F)google.com$([char]0x2F)” -SID $UserProfile.SID
    }

  • macxcool
    Participant
    Post count: 23

    This doesn’t work. Here’s my code:
    [scriptblock]$HKCURegistrySettings = {
    Set-RegistryKey -Key "HKCU\Software\SoftPlan Systems Inc.\SoftPlan Workstation\16.3.4\C:$([char]0x2F)Program Files$([char]0x2F)SoftPlan2014\SoftPlan Folders\" -Name 'Projects' -Value "S:$([char]0x2F)" -SID $UserProfile.SID
    }
    Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings

    This creates a series of keys named C: \ Program Files \ SoftPlan2014 \ SoftPlan Folders \ and then refuses to create the S:\ value because the Path doesn’t exist:

    [03-18-2016 09:06:22.428] [Post-Installation] [Set-RegistryKey] :: Failed to set value [S:/] for registry key [Registry::HKEY_CURRENT_USER\
    Software\SoftPlan Systems Inc.\SoftPlan Workstation\16.3.4\C:/Program Files/SoftPlan2014\SoftPlan Folders\] [Projects].
    Error Record:
    -------------

    Message : Cannot find path 'HKEY_CURRENT_USER\Software\SoftPlan Systems Inc.\SoftPlan Workstation\16.3.4\C:/Program
    Files/SoftPlan2014\SoftPlan Folders\' because it does not exist.
    InnerException :

    FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.NewItemPropertyCommand
    ScriptStackTrace : at Set-RegistryKey<Process>, \\5000m45\packagesource$\Software_8\Softplan_Educational_Workstation_2014\AppDeployTo
    olkit\AppDeployToolkitMain.ps1: line 3737
    at <ScriptBlock>, <No file>: line 1

    PositionMessage : At \\5000m45\packagesource$\Software_8\Softplan_Educational_Workstation_2014\AppDeployToolkit\AppDeployToolkitMain.ps1:3
    737 char:14
    + $null = New-ItemProperty -LiteralPath $key -Name $name -Value $value -Prope ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    • This reply was modified 1 year, 10 months ago by  macxcool.
  • macxcool
    Participant
    Post count: 23

    I apologize for the mess. I have no idea how to put in code nicely.

  • Pelle
    Participant
    Post count: 100

    Have you tried the apostrophe-like character ` in front of your slash character? It’s called grave accent according to ascii-code.com..

    DEC; OCT; HEX; BIN; Symbol; HTML; Number; HTML; Name; Description;
    96 140 60 01100000 ` ` Grave accent

    Now, this wysisyg is not very “character friendly” but your string would look something like this (if all characters are allowed in here):
    ‘HKCU\Software\X\https://google.com`/’

    Normally solves my scripts involving spooky characters.

    • This reply was modified 1 year, 10 months ago by  Pelle.
    • This reply was modified 1 year, 10 months ago by  Pelle. Reason: spelling
  • Pelle
    Participant
    Post count: 100

    Ok, my example of your string got messed up by the site, but I think you get it.. put one ` in front of every / and I think you’re good to go.

  • macxcool
    Participant
    Post count: 23

    Did you try it? It doesn’t work for me. I try

    Set-RegistryKey -Key “HKCU:\TEMPORARY’c:/temp/”

    and powershell still just interprets them as backslashes and gives me:
    HKCU \ TEMPORARY \ C: \ temp
    and
    HKCU \ TEMPORARY \ C: \ emp (for some reason)

  • macxcool
    Participant
    Post count: 23

    In the above post I did put backquotes in front of the forward slashes.

  • Pelle
    Participant
    Post count: 100

    No I didn’t try your script out. I did however run the following through a PS console without any issues:

    New-Item -Path HKCU:\SOFTWARE\TEST
    Set-ItemProperty -Name TESTURL -Value “http://www.google.com” -Path HKCU:\SOFTWARE\TEST\
    Set-ItemProperty -Name TESTPATH -Value “C://\.com” -Path HKCU:\SOFTWARE\TEST\

    Comes out as two REG_SZ strings with both slashes backslashes formatted correctly. The 2nd one obviously has a messed up value, but proved to me that came out as expected in the registry.

    Might be something in the Function Set-RegistryKey that messes things up. It does go beyond the normal PS cmdlets for adding items in the registry, so might be.

    Again, please mind the automatic formatting on the site. I did put a ` in front of every special character and surrounded the entire value string with quotation marks.

    • This reply was modified 1 year, 10 months ago by  Pelle.
    • This reply was modified 1 year, 10 months ago by  Pelle.
    • This reply was modified 1 year, 10 months ago by  Pelle. Reason: spelling + clarification
  • macxcool
    Participant
    Post count: 23

    I’m having problems with the key name, not the value of a property. I’ve created a bug report on the tracker for it that has more detail about what I’ve tried.
    I can’t seem to create a key with forward slashes in it or write to an existing key with the same. Values seem to work out fine.

  • macxcool
    Participant
    Post count: 23

    That’s a start. Thanks.
    If that works I’ve just got to figure out how to write a propery/value into a key with a forward slash in the name.

You must be logged in to reply to this topic.