bRaNdOn
bRaNdOn

Reputation: 1082

Creating Key in regedit with "/"in the name

Hi i'm just wondering im currently creating folder on my registry this is my code

function AddMachineRegistry{
    param(
    [string] $registryPath = $(throw "registryPath is a required parameter"),
    [string] $name = $(throw "name is a required parameter"),
    [int] $value = $(throw "value is a required parameter")
    )

    IF(!(Test-Path $registryPath))
    {
        New-Item -Path $registryPath -ItemType Key -Force | Out-Null     
    }

    New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType DWORD -force | Out-Null
}

and tried to used it like this

AddMachineRegistry "HKLM:\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 40/128\" "Enabled" 0

basically im trying to create a key with the name of "RC4 40/128" but when i execute it it creates "RC4 40" folder and under that it creates "128"

im just wondering is it possible to create that? since im currently using "New-Item" and just giving it a path. i want my folder to named "RC4 40/128"

Upvotes: 1

Views: 1282

Answers (2)

Maximilian Burszley
Maximilian Burszley

Reputation: 19704

The easiest way will be invoking & REG ADD (basically, using CMD for the task) since PowerShell wants to interpret the forward slash as a delimiter. I just had a problem at work recently where I ran into this problem and could not find any solutions beyond that one.

A small tip: | Out-Null is a very slow operation and if you plan on calling anything with it to scale, I'd recommend using $Null = or [Void]( ... )

Upvotes: 1

KlapenHz
KlapenHz

Reputation: 73

Normaly you must use:

New-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\" -Name "RC4 40/128" -PropertyType DWORD -Value 0

In this case it will we be:

AddMachineRegistry "HKLM:\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\" "RC4 40/128" 0

There is no need to backslashes the "/". Alternative: you can put path in ' ' instead " ". Commands in ' ' change special characters to normal chars.

Upvotes: 0

Related Questions