この質問で説明されているように、2 つの Web サイトを IE11 互換ビューに追加するレジストリ キーを作成しようとしています。
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData
キー UserFilter のタイプは REG_BINARY ですが、キーを調べたりエクスポートしたりすると、16 進文字列のように見えます。たとえば、手動で「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 で見たときの値のデータは、上記の 16 進文字列とはまったく異なります。私も試しました:
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 で見たときの値のデータは、上記の 16 進文字列とはまったく異なります。