将站点添加到 IE 中的受信任列表(高于 6 的所有版本)
本文关键字:高于 版本 添加 站点 IE 信任列表 | 更新日期: 2023-09-27 17:56:42
程序在
var 子域 = 新字典
Visual Studio所说的消息是"参数异常未处理"
我不确定如何解决它或它意味着什么?任何帮助将不胜感激。
使用系统;使用 System.Collections.Generic;使用System.Linq;使用系统文本;使用 Microsoft.Win32;命名空间 LotusTrustedSites{ 类报告下载器 { [统计] 静态空 主(字符串[] 参数) { const string domainKeyLocation = @"Software''Microsoft''Windows''CurrentVersion''Internet Settings''ZoneMap''Domains"; 常量字符串域 = @"newsite.com"; const int trustedSiteZone = 0x2; var 子域 = 新字典 { {"www", "https"}, {"www", "http"}, {"博客", "https"}, {"blog", "http"} }; RegistryKey currentUserKey = Registry.CurrentUser; currentUserKey.GetOrCreateSubKey(domainsKeyLocation, domain, false); foreach (子域中的 var 子域) { CreateSubdomainKeyAndValue(currentUserKey, domainKeyLocation, domain, subdomain, trustedSiteZone); }//自动化代码 } private static void CreateSubdomainKeyAndValue(RegistryKey currentUserKey, string domainKeyLocation, string domain, KeyValuePair subdomain, int zone) { RegistryKey subdomainRegistryKey = currentUserKey.GetOrCreateSubKey(string.格式(@"{0}''{1}", 域密钥位置, 域), 子域.键,真); object objSubDomainValue = subdomainRegistryKey.GetValue(subdomain.值); if (objSubDomainValue == null ||Convert.ToInt32(objSubDomainValue) != zone) { subdomainRegistryKey.SetValue(subdomain.Value, zone, RegistryValueKind.DWord); } } } 公共静态类 注册表键扩展方法 { public static RegistryKey GetOrCreateSubKey(this RegistryKey registryKey, string parentKeyLocation, string key, bool write itable) { 字符串键位置 = 字符串。格式(@"{0}''{1}", 父键位置, 键); RegistryKey foundRegistryKey = registryKey.OpenSubKey(keyLocation, writeitable); 返回找到注册表密钥??registryKey.CreateSubKey(parentKeyLocation, key); } 公共静态注册表键创建子项(此注册表键注册表项,字符串父键位置,字符串键) { RegistryKey parentKey = registryKey.OpenSubKey(parentKeyLocation, true);必须是可写的 == 真 if (父键 == 空) { 抛出新的 NullReferenceException(字符串。格式("缺少父键:{0}",父键位置)); } RegistryKey createdKey = parentKey.CreateSubKey(key); if (创建密钥 == 空) { 抛出新的异常(字符串。格式("密钥未创建:{0}",密钥)); } 返回创建的密钥; } }}
你有重复的键。 Dictionary
要求密钥是唯一的。