简体   繁体   English

如何通过 PowerShell cmdlet 将 REG_DWORD 值的基数从十六进制更改为十进制?

[英]How do I change a REG_DWORD value's base from Hexadecimal to Decimal via PowerShell cmdlets?

For a private preview tool provided by Microsoft, a registry value needs to be set to Type REG_DWORD value 46, then change the Base from hexadecimal to decimal.对于 Microsoft 提供的私人预览工具,需要将注册表值设置为 Type REG_DWORD 值 46,然后将 Base 从十六进制更改为十进制。 Here is a portion of the documentation I am referring to:这是我所指的文档的一部分:

  1. Use the Edit menu or right-click to create a new DWORD (32-bit) Value and name it WUfBDF (note the only lowercase letter in this name is the 3rd 'f' and all the rest are uppercase).使用编辑菜单或右键单击创建一个新的 DWORD(32 位)值并将其命名为 WUfBDF(注意此名称中唯一的小写字母是第 3 个“f”,其余全部为大写)。
  2. Next, right-click on the new value and select the Modify… option.接下来,右键单击新值并选择 Modify... 选项。
    Make sure to choose the Decimal base and set the value to 46.确保选择十进制基数并将值设置为 46。

I am creating a Proactive remediation script to push out to a group of machines that need this Reg key/item for the preview tool to work.我正在创建一个主动修复脚本,以推送到一组需要此 Reg 密钥/项目以使预览工具工作的机器。

$regkeyPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
$regEntry = "WUfBDF"
$desiredValue = 46

function createRegEntry($path, $entry, $value){
    write-output "Remediating registry entry."
    if(test-path -Path $path){
        write-output "$path exists. Setting $entry"
        Set-ItemProperty -Path $path -Name $entry -Value $value -Type DWord -force | out-null
    }else{
        New-Item -Path $Path -Force
        New-ItemProperty -Path $path -Name $entry -Value $value -PropertyType DWord -force | out-null
    }
}

createRegEntry $regkeyPath $regEntry $desiredValue

I read the Set-ItemProperty documentation here from Microsoft Documentation and it seems that when creating a REG-DWORD value its Base defaults to hex and has to manually be altered.我在这里从 Microsoft 文档中阅读了 Set-ItemProperty 文档,似乎在创建 REG-DWORD 值时,它的 Base 默认为十六进制并且必须手动更改。 Any way to change it to REG_DWORD with the Base as Decimal以十进制为基数将其更改为 REG_DWORD 的任何方法

The "base" option in the regedit UI is a convenience for the user. regedit UI 中的“base”选项为用户提供了便利。 The instructions could just as easily have said "set base to Hexadecimal and enter 2e" - they're both the same number.指令可以很容易地说“将基数设置为十六进制并输入 2e”——它们都是相同的数字。 Sometimes it's just easier to work with a hex number - eg 0xF000 (hex) instead of 61440 (decimal) or vice versa.有时使用十六进制数字更容易 - 例如0xF000 (十六进制)而不是61440 (十进制),反之亦然。

In fact, if you set the dialog to Decimal, enter 46 and then change to Hexadecimal you'll see the "Value data" change to 2e automatically...实际上,如果您将对话框设置为十进制,输入 46,然后更改为十六进制,您会看到“数值数据”自动更改为 2e...

在此处输入图像描述

在此处输入图像描述

And it shows both values in the main details pane:它在主要详细信息窗格中显示这两个值:

在此处输入图像描述

Similarly, when writing your PowerShell code you could write $desiredValue = 46 or $desiredValue = 0x2E and get the same result.同样,在编写 PowerShell 代码时,您可以编写$desiredValue = 46$desiredValue = 0x2E并获得相同的结果。 They're both representations of the same number - one decimal and one hexadecimal - it just depends on your preference which format you use.它们都是相同数字的表示 - 一个十进制和一个十六进制 - 这取决于您使用哪种格式的偏好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM