-PropertyType 设置为 DWord,但在创建 Item 时它以字符串形式出现

-PropertyType set as DWord but when Item is created it comes out as a string

我的代码:

try {
    if(!(Test-Path -Path $registryPath -Value $Name)) {
        New-ItemProperty -Name test -Path HKLM:\Software\WOW6432Node\Mozilla -PropertyType DWord -Value 2
    }
}
catch {
    Set-ItemProperty -Path $registryPath -Name $Name -Value $value 
}

我的问题:结果以字符串形式出现。

我试过将 -PropertyType 更改为 -Type
我试过改变 DWord.

这个词的首字母大写

如有任何帮助,我们将不胜感激。

正如the docs所说: 您还可以使用 Set-ItemProperty 创建和更改注册表值和数据。例如,您可以将一个新的注册表项添加到一个键并建立或更改它的值。

使用 Set-ItemProperty 还可以将注册表项的类型从 REG_SZ(字符串)值更改为 DWord,因此基本上您只需要:

$registryPath = 'HKLM:\Software\WOW6432Node\Mozilla'
$propName = 'test'

Set-ItemProperty -Path $registryPath -Name $propName -Value 2 -Type DWord

当然,如果您无权在 HKEY_LOCAL_MACHINE 注册表路径中创建或更改某些内容,您将收到错误消息。