如何通过powershell cmdlet将reg_dword值从十六进制更改为十进制?

发布于 2025-02-13 04:27:21 字数 1407 浏览 1 评论 0 原文

对于由Microsoft提供的私人预览工具,需要将注册表值设置为键入reg_dword值46,然后将基数从十六进制更改为十进制。 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) 值和命名wufbdf(请注意此处唯一的小写字母 名称是第三'f',其余的都是大写)。
  2. 接下来,右键单击新值,然后选择“修改…”选项。
    Make sure to choose the Decimal base and set the value to 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.

$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

我读了set-itemproperty文档此处来自Microsoft文档,似乎在创建时似乎reg-dword值的基本默认值是十六进制,必须手动更改。将其更改为reg_dword的任何方法都以十进制为基础

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. 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).
  2. Next, right-click on the new value and select the Modify… option.
    Make sure to choose the Decimal base and set the value to 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.

$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. Any way to change it to REG_DWORD with the Base as Decimal

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍孤女 2025-02-20 04:27:23

Regedit UI中的“基础”选项对于用户来说是一个方便。这些说明可以很容易地说“将基础设置为十六进制并输入2E” - 它们都是相同的数字。有时,使用十六进制号码 - 例如 0xf000 (HEX)而不是 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...

enter image description here

And it shows both values in the main details pane:

enter image description here

Similarly, when writing your PowerShell code you could write $desiredValue = 46 $ desiredValue = 0x2e 并获得相同的结果。它们都是相同数字的表示形式 - 一个小数点和一个十六进制 - 仅取决于您使用哪种格式。

The "base" option in the regedit UI is a convenience for the user. The instructions could just as easily have said "set base to Hexadecimal and enter 2e" - they're both the same number. Sometimes it's just easier to work with a hex number - e.g. 0xF000 (hex) instead of 61440 (decimal) or vice versa.

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...

enter image description here

enter image description here

And it shows both values in the main details pane:

enter image description here

Similarly, when writing your PowerShell code you could write $desiredValue = 46 or $desiredValue = 0x2E and get the same result. They're both representations of the same number - one decimal and one hexadecimal - it just depends on your preference which format you use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文