通过注册表添加网址到IE兼容视图 IE兼容视图注册表internet explorer二进制 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本帖最后由 net_lover 于 2014-04-20 10:09:40 编辑 这个页面的下面的代码可以实现http://stackoverflow.com/questions/16722454/editing-binary-registry-key前提是里面已经有值,你可以再改改测试例子,IE8+Windows 2003测试通过private const string CLEARABLE_LIST_DATA = @"Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData"; private const string USERFILTER = "UserFilter"; private static string[] GetDomains() { string[] domains; using (Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(CLEARABLE_LIST_DATA)) { byte[] filter = regkey.GetValue(USERFILTER) as byte[]; domains = GetDomains(filter); } return domains; } /* IT'S DANGER!! */ // You shouldn't call until it becomes completely obvious that UNKNOWN parameter is meaning. private static void AddUserFilter(string domain) { string[] domains = GetDomains(); foreach (string item in domains) { if (item == domain) { return; } } using (Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(CLEARABLE_LIST_DATA)) { byte[] filter = regkey.GetValue(USERFILTER) as byte[]; if (filter == null) filter = new byte[0]; byte[] newReg = GetAddedValue(domain, filter); regkey.SetValue(USERFILTER, newReg, Microsoft.Win32.RegistryValueKind.Binary); } } private static void RemoveUserFilter(string domain) { using (Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(CLEARABLE_LIST_DATA)) { byte[] filter = regkey.GetValue(USERFILTER) as byte[]; byte[] newReg = GetRemovedValue(domain, filter); if (GetDomains(newReg).Length == 0) regkey.DeleteValue(USERFILTER); else regkey.SetValue(USERFILTER, newReg, Microsoft.Win32.RegistryValueKind.Binary); } } private static byte[] GetFilter() { byte[] filter; using (Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(CLEARABLE_LIST_DATA)) { filter = regkey.GetValue(USERFILTER) as byte[]; } return filter; } private static string[] GetDomains(byte[] filter) { List<string> domains = new List<string>(); int length; int offset_filter = 24; int totalSize = filter.Length; while (offset_filter < totalSize) { length = BitConverter.ToUInt16(filter, offset_filter + 16); domains.Add(System.Text.Encoding.Unicode.GetString(filter, 16 + 2 + offset_filter, length * 2)); offset_filter += 16 + 2 + length * 2; } return domains.ToArray(); } private static byte[] GetAddedValue(string domain, byte[] filter) { byte[] SEPARATOR = new byte[] { 0x0C, 0x00, 0x00, 0x00 }; byte[] CONSTANT = new byte[] { 0x01, 0x00, 0x00, 0x00 }; byte[] UNKNOWN = BitConverter.GetBytes(DateTime.Now.ToBinary()); List<byte> newReg = new List<byte>(); byte[] binDomain = System.Text.Encoding.Unicode.GetBytes(domain); newReg.AddRange(filter); newReg.AddRange(SEPARATOR); /************************************************************************************************/ newReg.AddRange(UNKNOWN); // IT'S IRRESPONSIBLE!! Setting 0x00 is preferable to adding DateTime /************************************************************************************************/ newReg.AddRange(CONSTANT); newReg.AddRange(BitConverter.GetBytes((UInt16)domain.Length)); newReg.AddRange(binDomain); byte[] newSize = BitConverter.GetBytes((UInt16)(newReg.Count - 12)); newReg[12] = newSize[0]; newReg[13] = newSize[1]; string[] domains = GetDomains(); byte[] newCount = BitConverter.GetBytes((UInt16)(domains.Length + 1)); newReg[8] = newCount[0]; newReg[9] = newCount[1]; newReg[20] = newCount[0]; newReg[21] = newCount[1]; return newReg.ToArray(); } private static byte[] GetRemovedValue(string domain, byte[] filter) { byte[] newReg; int length; int offset_filter = 24; int offset_newReg = 0; int totalSize = filter.Length; newReg = new byte[totalSize]; Array.Copy(filter, 0, newReg, 0, offset_filter); offset_newReg += offset_filter; while (offset_filter < totalSize) { length = BitConverter.ToUInt16(filter, offset_filter + 16); if (domain != System.Text.Encoding.Unicode.GetString(filter, offset_filter + 16 + 2, length * 2)) { Array.Copy(filter, offset_filter, newReg, offset_newReg, 16 + 2 + length * 2); offset_newReg += 16 + 2 + length * 2; } offset_filter += 16 + 2 + length * 2; } Array.Resize(ref newReg, offset_newReg); byte[] newSize = BitConverter.GetBytes((UInt16)(offset_newReg - 12)); newReg[12] = newSize[0]; newReg[13] = newSize[1]; return newReg; } private void Form1_Load(object sender, EventArgs e) { AddUserFilter("meng.com"); } 完整代码发布在https://code.csdn.net/snippets/302829请查收 asp.net管理系统给客户分配不同的账号,客户登陆后跳转到不同的页面? 新手提问:如何取字段的数据类型?SQL语句能做到么? 怎样把combobox设置为只读啊,网上说style属性,可是没这个属性啊? 求一个简单的酒店管理系统 datagrid添加控件。 函数返回NULL表示什么(C#和C++分别回答) 那位太阳 键个 学习的群吧. 请教各位网友“鎮ㄥソ锛”是什么意思啊,谢谢! 自定义组件设计中,如何通过attribute,使arraylist型的属性在设计时可通过属性编辑器进行输入值 高手进来看一下 c#工程向c++工程传参 Dev TreeList怎么取隐藏列的值?
http://stackoverflow.com/questions/16722454/editing-binary-registry-key前提是里面已经有值,你可以再改改测试例子,IE8+Windows 2003测试通过
private const string CLEARABLE_LIST_DATA = @"Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData";
private const string USERFILTER = "UserFilter"; private static string[] GetDomains()
{
string[] domains; using (Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(CLEARABLE_LIST_DATA))
{
byte[] filter = regkey.GetValue(USERFILTER) as byte[];
domains = GetDomains(filter);
} return domains;
} /* IT'S DANGER!! */
// You shouldn't call until it becomes completely obvious that UNKNOWN parameter is meaning.
private static void AddUserFilter(string domain)
{
string[] domains = GetDomains();
foreach (string item in domains)
{
if (item == domain)
{
return;
}
} using (Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(CLEARABLE_LIST_DATA))
{
byte[] filter = regkey.GetValue(USERFILTER) as byte[];
if (filter == null) filter = new byte[0];
byte[] newReg = GetAddedValue(domain, filter); regkey.SetValue(USERFILTER, newReg, Microsoft.Win32.RegistryValueKind.Binary);
}
} private static void RemoveUserFilter(string domain)
{
using (Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(CLEARABLE_LIST_DATA))
{
byte[] filter = regkey.GetValue(USERFILTER) as byte[];
byte[] newReg = GetRemovedValue(domain, filter); if (GetDomains(newReg).Length == 0)
regkey.DeleteValue(USERFILTER);
else
regkey.SetValue(USERFILTER, newReg, Microsoft.Win32.RegistryValueKind.Binary);
}
} private static byte[] GetFilter()
{
byte[] filter;
using (Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(CLEARABLE_LIST_DATA))
{
filter = regkey.GetValue(USERFILTER) as byte[];
}
return filter;
} private static string[] GetDomains(byte[] filter)
{
List<string> domains = new List<string>(); int length;
int offset_filter = 24;
int totalSize = filter.Length; while (offset_filter < totalSize)
{
length = BitConverter.ToUInt16(filter, offset_filter + 16);
domains.Add(System.Text.Encoding.Unicode.GetString(filter, 16 + 2 + offset_filter, length * 2));
offset_filter += 16 + 2 + length * 2;
} return domains.ToArray();
} private static byte[] GetAddedValue(string domain, byte[] filter)
{
byte[] SEPARATOR = new byte[] { 0x0C, 0x00, 0x00, 0x00 };
byte[] CONSTANT = new byte[] { 0x01, 0x00, 0x00, 0x00 };
byte[] UNKNOWN = BitConverter.GetBytes(DateTime.Now.ToBinary()); List<byte> newReg = new List<byte>();
byte[] binDomain = System.Text.Encoding.Unicode.GetBytes(domain); newReg.AddRange(filter);
newReg.AddRange(SEPARATOR);
/************************************************************************************************/
newReg.AddRange(UNKNOWN); // IT'S IRRESPONSIBLE!! Setting 0x00 is preferable to adding DateTime
/************************************************************************************************/
newReg.AddRange(CONSTANT);
newReg.AddRange(BitConverter.GetBytes((UInt16)domain.Length));
newReg.AddRange(binDomain); byte[] newSize = BitConverter.GetBytes((UInt16)(newReg.Count - 12));
newReg[12] = newSize[0];
newReg[13] = newSize[1]; string[] domains = GetDomains();
byte[] newCount = BitConverter.GetBytes((UInt16)(domains.Length + 1));
newReg[8] = newCount[0];
newReg[9] = newCount[1]; newReg[20] = newCount[0];
newReg[21] = newCount[1]; return newReg.ToArray();
} private static byte[] GetRemovedValue(string domain, byte[] filter)
{
byte[] newReg;
int length;
int offset_filter = 24;
int offset_newReg = 0;
int totalSize = filter.Length; newReg = new byte[totalSize];
Array.Copy(filter, 0, newReg, 0, offset_filter);
offset_newReg += offset_filter; while (offset_filter < totalSize)
{
length = BitConverter.ToUInt16(filter, offset_filter + 16);
if (domain != System.Text.Encoding.Unicode.GetString(filter, offset_filter + 16 + 2, length * 2))
{
Array.Copy(filter, offset_filter, newReg, offset_newReg, 16 + 2 + length * 2);
offset_newReg += 16 + 2 + length * 2;
}
offset_filter += 16 + 2 + length * 2;
}
Array.Resize(ref newReg, offset_newReg);
byte[] newSize = BitConverter.GetBytes((UInt16)(offset_newReg - 12));
newReg[12] = newSize[0];
newReg[13] = newSize[1]; return newReg;
}
private void Form1_Load(object sender, EventArgs e)
{
AddUserFilter("meng.com");
}
https://code.csdn.net/snippets/302829
请查收