通过C#在Windows注册表中创建REG_NONE空值 [英] Create a REG_NONE empty value in the Windows Registry via C#

查看:336
本文介绍了通过C#在Windows注册表中创建REG_NONE空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在类型为REG_NONE的Windows注册表中创建一个空值?

例如,对于此密钥:

 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\
  .htm\OpenWithProgids
 

以下是我在Windows 7计算机上看到的值:

 ----------------------------------------------------
Name           Type       Data
----------------------------------------------------
(Default)      REG_SZ     (value not set)
FirefoxHTML    REG_NONE   (zero-length binary value)
htmlfile       REG_NONE   (zero-length binary value)
----------------------------------------------------
 

具体来说,我如何声明和初始化类型为零长度二进制值"的变量,以将其传递给解决方案

[这是我的研究结果.]

我在Microsoft的 RegistryKey的参考源中找到了正在寻找的提示. .cs :

 byte[] value = new byte[0];
 

具体来说,调用 RegistryKey.SetValue 其中:

  using Microsoft.Win32;

 RegistryKey key; // set via 'CreateSubKey' or 'OpenSubKey'
 key.SetValue("KeyName", new byte[0], RegistryValueKind.None);
 

但是,请注意,至少对于出现在OpenWithProgids键中的值,Windows似乎也将空字符串值视为等效:

  key.SetValue("KeyName", string.Empty, RegistryValueKind.String);
 

例如,对于此密钥:

 HKEY_CLASSES_ROOT\.vcxproj\OpenWithProgids
 

以下是我在计算机上看到的值:

 ---------------------------------------------------------------
Name                                  Type      Data
---------------------------------------------------------------
(Default)                             REG_SZ    (value not set)
Expression.Blend.vcsproj.12.0         REG_SZ
VisualStudio.Launcher.vcxproj.10.0    REG_SZ
VisualStudio.Launcher.vcxproj.12.0    REG_SZ
VisualStudio.vcxproj.10.0             REG_SZ
VisualStudio.vcxproj.12.0             REG_SZ
---------------------------------------------------------------
 

相关:请参见此答案HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\ .htm\OpenWithProgids

Here are the values that I see on my Windows 7 machine:

----------------------------------------------------
Name           Type       Data
----------------------------------------------------
(Default)      REG_SZ     (value not set)
FirefoxHTML    REG_NONE   (zero-length binary value)
htmlfile       REG_NONE   (zero-length binary value)
----------------------------------------------------

Specifically, how do I declare and initialize a variable of type "zero-length binary value" for the purpose of passing it to RegistryKey.SetValue? Note that I could not find the help that I needed in the documentation for the RegistryValueKind enumeration.

解决方案

[Here is the result of my research.]

I found the hint I was looking for in Microsoft's reference source for RegistryKey.cs:

byte[] value = new byte[0];

Specifically, call RegistryKey.SetValue where:

 using Microsoft.Win32;

 RegistryKey key; // set via 'CreateSubKey' or 'OpenSubKey'
 key.SetValue("KeyName", new byte[0], RegistryValueKind.None);

However, note that at least for values that appear in an OpenWithProgids key, Windows also appears to treat empty string values as equivalent:

 key.SetValue("KeyName", string.Empty, RegistryValueKind.String);

For instance, for this key:

HKEY_CLASSES_ROOT\.vcxproj\OpenWithProgids

Here are the values that I see on my machine:

---------------------------------------------------------------
Name                                  Type      Data
---------------------------------------------------------------
(Default)                             REG_SZ    (value not set)
Expression.Blend.vcsproj.12.0         REG_SZ
VisualStudio.Launcher.vcxproj.10.0    REG_SZ
VisualStudio.Launcher.vcxproj.12.0    REG_SZ
VisualStudio.vcxproj.10.0             REG_SZ
VisualStudio.vcxproj.12.0             REG_SZ
---------------------------------------------------------------

Related: See this answer and this answer for examples for how to set the data of a Registry value of type RegistryValueKind.Binary to a non-empty byte array.

这篇关于通过C#在Windows注册表中创建REG_NONE空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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