在IE中将站点添加到受信任列表(所有6以上版本)

该程序崩溃

var subdomain =新词典

Visual Studio所说的消息是“参数异常未处理”

我不知道如何解决它或它的意思? 任何帮助,将不胜感激。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace LotusTrustedSites
{       
    class ReportDownloader    
    {        
        [STAThread]        
        static void Main(string[] args)        
        {            
            const string domainsKeyLocation = @"SoftwareMicrosoftWindowsCurrentVersionInternet SettingsZoneMapDomains";            
            const string domain = @"newsite.com";            
            const int trustedSiteZone = 0x2;            
            var subdomains = new Dictionary
                {                                     
                    {"www", "https"},                                     
                    {"www", "http"},                                     
                    {"blog", "https"},                                     
                    {"blog", "http"}                                 
                };            
            RegistryKey currentUserKey = Registry.CurrentUser;            
            currentUserKey.GetOrCreateSubKey(domainsKeyLocation, domain, false);            
            foreach (var subdomain in subdomains)            
            {                
                CreateSubdomainKeyAndValue(currentUserKey, domainsKeyLocation, domain, subdomain, trustedSiteZone);            
            }            //automation code        
        }        

        private static void CreateSubdomainKeyAndValue(RegistryKey currentUserKey, string domainsKeyLocation, string domain, KeyValuePair subdomain, int zone)        
        {            
            RegistryKey subdomainRegistryKey = currentUserKey.GetOrCreateSubKey(string.Format(@"{0}{1}", domainsKeyLocation, domain), subdomain.Key, true);            
            object objSubDomainValue = subdomainRegistryKey.GetValue(subdomain.Value);            
            if (objSubDomainValue == null || Convert.ToInt32(objSubDomainValue) != zone)            
            {                
                subdomainRegistryKey.SetValue(subdomain.Value, zone, RegistryValueKind.DWord);            
            }        
        }    
    }    
    public static class 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);            
            return foundRegistryKey ?? registryKey.CreateSubKey(parentKeyLocation, key);        
        }        
        public static RegistryKey CreateSubKey(this RegistryKey registryKey, string parentKeyLocation, string key)        
        {            
            RegistryKey parentKey = registryKey.OpenSubKey(parentKeyLocation, true); //must be writable == true            
            if (parentKey == null) 
            { 
                throw new NullReferenceException(string.Format("Missing parent key: {0}", parentKeyLocation)); 
            }            
            RegistryKey createdKey = parentKey.CreateSubKey(key);            
            if (createdKey == null) 
            { 
                throw new Exception(string.Format("Key not created: {0}", key)); 
            }            
            return createdKey;        
        }    
    }
}

你有重复的密钥。 Dictionary要求键是唯一的。

链接地址: http://www.djcxy.com/p/53777.html

上一篇: Adding sites to Trusted list in IE (all versions above 6)

下一篇: Interesting use of the C# yield keyword in Nerd Dinner tutorial