我正在尝试创建一个注册表项,将两个网站添加到 IE11s 兼容性视图中,在这个问题中进行了描述:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData
键 UserFilter 是 REG_BINARY 类型,但是当您查看该键或导出它时,它似乎是一个十六进制字符串。例如,当我手动将“example1.com”和“example2.com”添加到列表中,然后导出密钥时,它的内容如下:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData]
"UserFilter"=hex:41,1f,00,00,53,08,ad,ba,02,00,00,00,60,00,00,00,01,00,00,00,\
02,00,00,00,0c,00,00,00,4f,af,fc,87,ab,20,d1,01,01,00,00,00,0c,00,65,00,78,\
00,61,00,6d,00,70,00,6c,00,65,00,31,00,2e,00,63,00,6f,00,6d,00,0c,00,00,00,\
cf,52,f5,89,ab,20,d1,01,01,00,00,00,0c,00,65,00,78,00,61,00,6d,00,70,00,6c,\
00,65,00,32,00,2e,00,63,00,6f,00,6d,00
我正在尝试在 c# 中创建此密钥,但这样做有很多麻烦。这是我到目前为止所尝试的:
RegistryKey regKey1 = default(RegistryKey);
regKey1 = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\BrowserEmulation\\ClearableListData", true);
string hexString = @"41,1f,00,00,53,08"... etc from above
var byteArr = ConvertToByteArray(hexString, Encoding.Default);
regKey1.SetValue("UseFilter", byteArr, RegistryValueKind.Binary);
regKey1.Close();
//...
public static byte[] ConvertToByteArray(string str, Encoding encoding)
{
return encoding.GetBytes(str);
}
这不起作用。它添加了一个键,但是在regedit中查看它时的值数据与上面的十六进制字符串完全不同。我也试过:
regKey1.SetValue("UserFilter", hexString, RegistryValueKind.Binary); // Does not work, The type of the value object did not match the specified RegistryValueKind
regKey1.SetValue("UserFilter", hexString, RegistryValueKind.String); // Adds the key, but obviously makes it type REG_SZ and therefore does not work
regKey1.SetValue("UserFilter", hexString, RegistryValueKind.Unknown); // Does the same thing as adding a string
这是因为我在ConvertToByteArray
函数上使用了错误的编码吗?我如何编写 hexString 有问题吗?是否有另一种方法可以将网站添加到REG_BINARY
密钥?
编辑:
我也尝试了所有不同的编码ConvertToByteArray
,但我遇到了和以前一样的问题——在 regedit 中查看它时的值数据与上面的十六进制字符串完全不同。