【问题标题】:Adding sites to Trusted list in IE (all versions above 6)将站点添加到 IE 中的受信任列表(6 以上的所有版本)
【发布时间】:2011-08-28 02:11:18
【问题描述】:

程序崩溃了

var subdomain = 新字典

Visual Studio 的消息是“Argument exception was unhandled”

我不确定如何修复它或它意味着什么?任何帮助将不胜感激。

使用系统; 使用 System.Collections.Generic; 使用 System.Linq; 使用 System.Text; 使用 Microsoft.Win32; 命名空间 LotusTrustedSites { 类报告下载器 { [STA线程] 静态无效主要(字符串 [] 参数) { 常量字符串 domainKeyLocation = @"软件\微软\Windows\CurrentVersion\Internet 设置\ZoneMap\Domains"; 常量字符串域 = @“newsite.com”; 常量 inttrustedSiteZone = 0x2; var subdomains = 新字典 { {"www", "https"}, {"www", "http"}, {"博客", "https"}, {“博客”,“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.Format(@"{0}\{1}", domainKeyLocation, domain), subdomain.Key, true); 对象 objSubDomainValue = subdomainRegistryKey.GetValue(subdomain.Value); if (objSubDomainValue == null || Convert.ToInt32(objSubDomainValue) != zone) { subdomainRegistryKey.SetValue(subdomain.Value, zone, RegistryValueKind.DWord); } } } 公共静态类 RegistryKeyExtensionMethods { public static RegistryKey GetOrCreateSubKey(this RegistryKey registryKey, string parentKeyLocation, string key, bool writable) { string keyLocation = string.Format(@"{0}\{1}", parentKeyLocation, key); RegistryKey foundRegistryKey = registryKey.OpenSubKey(keyLocation, writable); 返回foundRegistryKey ?? registryKey.CreateSubKey(parentKeyLocation, key); } public static RegistryKey CreateSubKey(this RegistryKey registryKey, string parentKeyLocation, string key) { RegistryKey parentKey = registryKey.OpenSubKey(parentKeyLocation, true); //必须是可写的 == true if (parentKey == null) { throw new NullReferenceException(string.Format("缺少父键:{0}", parentKeyLocation)); } RegistryKey createdKey = parentKey.CreateSubKey(key); if (createdKey == null) { throw new Exception(string.Format("Key not created: {0}", key)); } 返回创建的密钥; } } }

【问题讨论】:

    标签: c# .net registry


    【解决方案1】:

    您有重复的键。 Dictionary 要求键是唯一的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-14
      • 2010-11-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-31
      相关资源
      最近更新 更多