C# 以编程方式将网站添加到c中的IE11兼容性视图#
我正在尝试创建一个注册表项,将两个网站添加到IE11s兼容性视图中,如中所述: key UserFilter是REG_BINARY类型,但当您查看或导出该键时,它似乎是一个十六进制字符串。例如,当我手动将“example1.com”和“example2.com”添加到列表中,然后导出密钥时,其内容如下:C# 以编程方式将网站添加到c中的IE11兼容性视图#,c#,.net,registry,internet-explorer-11,ie-compatibility-mode,C#,.net,Registry,Internet Explorer 11,Ie Compatibility Mode,我正在尝试创建一个注册表项,将两个网站添加到IE11s兼容性视图中,如中所述: key UserFilter是REG_BINARY类型,但当您查看或导出该键时,它似乎是一个十六进制字符串。例如,当我手动将“example1.com”和“example2.com”添加到列表中,然后导出密钥时,其内容如下: Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Internet Expl
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
函数上使用了错误的编码吗?我如何编写十六进制字符串有问题吗?是否有其他方法将网站添加到REG\u二进制
键
编辑:
我还尝试了ConvertToByteArray中的所有不同编码,但我遇到了与以前相同的问题-在regedit中查看值数据时,它与上面的十六进制字符串完全不同。我在这里找到了答案:-。有两个问题
hexString
包含换行符RegistryKey regKey1 = default(RegistryKey);
regKey1 = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\BrowserEmulation\\ClearableListData", true);
string hexString = "41,1f,00,00,53,08" + //next line... etc from above
var data = hexString.Split(',').Select(x => Convert.ToByte(x, 16)).ToArray();
regKey1.SetValue("UserFilter", data, RegistryValueKind.Binary);
regKey1.Close();
RegistryKey regKey1 = default(RegistryKey);
regKey1 = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\BrowserEmulation\\ClearableListData", true);
string hexString = "41,1f,00,00,53,08" + //next line... etc from above
var data = hexString.Split(',').Select(x => Convert.ToByte(x, 16)).ToArray();
regKey1.SetValue("UserFilter", data, RegistryValueKind.Binary);
regKey1.Close();