[英]Set a hex registry value with PowerShell
I have a Registration Entries (.reg) file, and I wanted to convert it to a PowerShell script.我有一个注册条目 (.reg) 文件,我想将其转换为 PowerShell 脚本。
On my way, I encountered this value: hex:00
.在路上,我遇到了这个值:
hex:00
。
Here is the registry key & value that I want to set:这是我要设置的注册表项和值:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{042D8A51-5878-4000-9C10-C04AFF122A1F}"
"Triggers"=hex:00
How do I set this Hex value using Set-ItemPropery?如何使用 Set-ItemPropery 设置此十六进制值?
When you use Set-ItemProperty
to target registry paths, the cmdlet supports a dynamic parameter named -Type
that accepts a Microsoft.Win32.RegistryValueKind
value, which specifies the value's data type.当您使用
Set-ItemProperty
来定位注册表路径时,该 cmdlet 支持名为-Type
的动态参数,该参数接受Microsoft.Win32.RegistryValueKind
值,该值指定值的数据类型。
The presence of hex:
in your *.reg
file implies binary (raw bytes) as the data type; hex:
在您的*.reg
文件中的存在意味着二进制(原始字节)作为数据类型; therefore:所以:
Binary
to -Type
Binary
传递给-Type
-Value
;-Value
; to produce the equivalent of hex:00
- ie a single byte with value 0x0
- use -Value 0x0
(to pass multiple bytes, separate them with ,
eg: -Value 0x0, 0x1
):hex:00
- 即值为0x0
的单个字节 - 使用-Value 0x0
(传递多个字节,用 分隔它们,
例如: -Value 0x0, 0x1
):Set-ItemProperty -Type Binary -Value 0x0 -Name Triggers -LiteralPath 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{042D8A51-5878-4000-9C10-C04AFF122A1F}'
Also note the registry::
prefix to the registry key path, which is required to identify the path as a registry path (in a context-independent manner).另请注意注册表项路径的
registry::
前缀,这是将路径标识为注册表路径所必需的(以与上下文无关的方式)。
Alternatively, replace registry::HKEY_LOCAL_MACHINE
with HKLM:
, to base the path on the equivalent PowerShell-specific drive instead.或者,将
registry::HKEY_LOCAL_MACHINE
替换为HKLM:
,以将路径基于等效的特定于 PowerShell 的驱动器。 (The other predefined registry drive is HKCU:
, which is equivalent to registry::HKEY_CURRENT_USER
; Get-PSDrive
-PSProvider registry
shows all registry-based drives). (另一个预定义的注册表驱动器是
HKCU:
,相当于registry::HKEY_CURRENT_USER
; Get-PSDrive
-PSProvider registry
显示所有基于注册表的驱动器)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.