如何编辑部分注册表值

如何编辑部分注册表值

我正在寻找从注册表值中删除最后 3 个字母的方法。

例子:

注册表项\软件\测试]

"设置"="ABCD

我希望事情能这样结束:

[HKEY_CURRENT_USER\Softw是\测试]

"设置"="ABC

它总是 6 个字母,而我总是想删除最后 3 个字母。我更喜欢使用 GPO 来实现这一点。

谢谢!

问候 Fredrik

答案1

由于它很短,因此您可能会从以下部分开始:

$registryPath = "HKCU:\Software\Test\" #reg key
$Name         = "setting"              #reg value
$value        = "ABCDDD"               #default value if does not exist

IF(!(Test-Path $registryPath))
{
    #Key does not exist, create key and set default
    New-Item -Path $registryPath -Force | Out-Null
    New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType String -Force | Out-Null
}
ELSE 
{
    #Key exists, read existing value and trim
    $strValue = (Get-ItemProperty -Path $registryPath).($Name)
    $strNew   = $strValue.SubString(0,3)
    New-ItemProperty -Path $registryPath -Name $name -Value $strNew -PropertyType String -Force | Out-Null
}

相关内容