C#为IE添加可信任站点

添加引用

1 using Microsoft.Win32;

1.添加域名站点,例如http://www.baidu.com

1          //以添加www.baidu.com为例
2          RegistryKey hkml = Registry.CurrentUser;//读取HKEY_CURRENT_USER
3          string address = @"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\INTERNET SETTINGS\ZONEMAP\Domains";
4          RegistryKey key1 = hkml.OpenSubKey(address, true);
5          RegistryKey baidu = key1.CreateSubKey("baidu.com");//新建项  baidu.com按需求替换
6          RegistryKey ww = baidu.CreateSubKey("www");//新建子项  www按需求替换
7          ww.SetValue("https", 0x2, RegistryValueKind.DWord);//赋值

2.添加IP地址站点,例如http://218.66.55.77

1          //以添加218.66.55.77为例
2          RegistryKey hkml = Registry.CurrentUser;//读取HKEY_CURRENT_USER     
3          string address = @"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\INTERNET SETTINGS\ZONEMAP\RANGES";
4          RegistryKey key1 = hkml.OpenSubKey(address, true);
5          RegistryKey Name1 = key1.CreateSubKey("Name1");//新建项  //Name1可随便改
6          Name1.SetValue(":Range", "218.66.55.77", RegistryValueKind.String);//赋值  218.66.55.77按需求修改
7          Name1.SetValue("http", 0x2, RegistryValueKind.DWord);//赋值

 

 

posted @ 2012-11-13 20:55  Rwen  阅读(2600)  评论(0编辑  收藏  举报