如何使用 PowerShell 设置二进制注册表值 (REG_BINARY)? [英] How to set a binary registry value (REG_BINARY) with PowerShell?
问题描述
如何使用 PowerShell 设置二进制注册表值 (REG_BINARY)?
How to set a binary registry value (REG_BINARY) with PowerShell?
背景:
我需要使用 PowerShell 脚本更改 ASP.NET 状态服务的某些属性.遗憾的是,内置的 PowerShell cmdlet Set-Service
只允许您修改服务描述、启动类型、显示名称和状态.我需要修改在 Recovery 选项卡上找到的 Subsequent failures
属性(查看服务的属性时).我发现该值作为 REG_BINARY 值存储在注册表中.
I need to change some properties of the ASP.NET State service using a PowerShell script. Unfortunately, the built-in PowerShell cmdlet Set-Service
only lets you modify the service description, startup type, display name, and status. I need to modify the Subsequent failures
property found on the Recovery tab (when viewing the service's properties). I found that this value was stored in the registry as a REG_BINARY value.
值的导出如下所示:
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\aspnet_state]
"FailureActions"=hex:50,33,01,00,00,00,00,00,00,00,00,00,03,00,00,00,0e,00,00,\
00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00
在 Powershell 中有一个 Set-ItemProperty
cmdlet,您可以使用它来设置注册表值.对于字符串或 dword 值,您可以只传递一个字符串或一个 int.我知道要更改数组中的哪个十六进制值,但我不知道如何设置二进制值.
In Powershell there is a Set-ItemProperty
cmdlet with which you can set registry value values. For a string or dword value, you can just pass a string or an int. I know which hex value in the array to change, but I can't figure out how to set a binary value.
推荐答案
下面这行给你一个如何创建一个的例子
The following line gives you an example how to create one
New-ItemProperty -Path . -Name Test -PropertyType Binary -Value ([byte[]](0x30,0x31,0xFF))
以及如何更改现有的:
Set-ItemProperty -Path . -Name Test -Value ([byte[]](0x33,0x32,0xFF))
这篇关于如何使用 PowerShell 设置二进制注册表值 (REG_BINARY)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!