Set-ItemProperty 在某些系统上将注册表值设置为字符串而不是双字,为什么? [英] Set-ItemProperty sets Registry Value as String on some systems instead of DWord, why?

查看:80
本文介绍了Set-ItemProperty 在某些系统上将注册表值设置为字符串而不是双字,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 PowerShell 中使用 Set-ItemProperty 创建一个项目,它适用于大多数系统:

I try to create an item using Set-ItemProperty in PowerShell, which works on most systems:

New-PSDrive -name HKCR -PSProvider Registry -root HKEY_CLASSES_ROOT

Set-ItemProperty -Path HKCR:\Software\MyCompany\ -Name Level -Value 5 -ErrorAction SilentlyContinue 

这会在大多数 Windows 7 系统上创建一个 DWORD 值,但我发现有一个系统会创建一个 STRING 值,我想知道:为什么?系统行为不同会发生什么?所有尚未设置该值,所有使用相同的 Powershell 版本使用相同的基础映像.

This creates a DWORD-value on most Windows 7 systems, but I have found one system where this creates a STRING-value instead, and I want to know: why? What could happen that the systems behave differently? All don't have that value already set, all use the same base image using the same Powershell version.

顺便说一句,我发现通过使用下面的代码,我可以显式设置一个类型,所以我已经解决了问题:

Btw, I found that by using the following code, I can explicitly set a type, so I already solved the problem:

New-ItemProperty -Path HKCR:\Software\MyCompany\ -Name Level -Value 5 -ErrorAction SilentlyContinue -PropertyType DWord

但出于好奇,我想知道为什么系统的行为不同.

But just for curiosity, I want to know why the systems behave differently.

推荐答案

我不知道为什么会发生这种情况,但要避免此类情况,请明确说明.使用类型(动态)参数并指定一个 RegistryValueKind 值(您也可以与 New-ItemProperty 一起使用):

I don't have an answer to why it happens but to avoid such instances, be explicit. Use the Type (dynamic) Parameter and specify a RegistryValueKind value (you can also use it with New-ItemProperty) :

Set-ItemProperty -Path HKCR:\Software\MyCompany -Name Level -Value 5 -Type DWord

这篇关于Set-ItemProperty 在某些系统上将注册表值设置为字符串而不是双字,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆