当前位置: 首页>>代码示例>>C#>>正文


C# Win32.RegistryKey类代码示例

本文整理汇总了C#中Microsoft.Win32.RegistryKey的典型用法代码示例。如果您正苦于以下问题:C# RegistryKey类的具体用法?C# RegistryKey怎么用?C# RegistryKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RegistryKey类属于Microsoft.Win32命名空间,在下文中一共展示了RegistryKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RegisterFile

        private static void RegisterFile(string path, RegistryKey root)
        {
            try
            {
				string userPath = GetUserFilePath(Path.GetFileName(path));
				string assembly = Assembly.GetExecutingAssembly().Location;
                string folder = Path.GetDirectoryName(assembly).ToLowerInvariant();
                string file = Path.Combine(folder, path);

                if (!File.Exists(file))
                    return;

				File.Copy(file, userPath, true);

				using (RegistryKey key = root.OpenSubKey("JavaScriptLanguageService", true))
                {
                    if (key == null)
                        return;

                    key.SetValue("ReferenceGroups_WE", "Implicit (Web)|" + userPath + ";");
                    return;
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
开发者ID:venux,项目名称:WebEssentials2015,代码行数:28,代码来源:JavaScriptIntellisense.cs

示例2: GetItemsFromRegistry

        protected List<SoftwareDTOResponse> GetItemsFromRegistry(RegistryKey key, string path)
        {
            List<SoftwareDTOResponse> software = new List<SoftwareDTOResponse>();

            using (RegistryKey rk = key.OpenSubKey(path))
            {
                foreach (string skName in rk.GetSubKeyNames())
                {
                    using (RegistryKey sk = rk.OpenSubKey(skName))
                    {
                        try
                        {
                            SoftwareDTOResponse application = new SoftwareDTOResponse();
                            application.Label = sk.GetValue("DisplayName").ToString();
                            application.ModelName = application.Label;
                            application.Version = sk.GetValue("DisplayVersion").ToString();
                            application.Path = sk.GetValue("Publisher").ToString() +
                                               " - " +
                                               application.Label +
                                               " - " +
                                               application.Version;

                            software.Add(application);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            return software;
        }
开发者ID:jjagodzinski,项目名称:ralph,代码行数:32,代码来源:WindowsRegistryDetectorSource.cs

示例3: Add

 public AddinsKey Add(string name, RegistryKey rootPath, string registryPath)
 {
     AddinsKey newItem = new AddinsKey(_parent, name, rootPath, registryPath);
     _items.Add(newItem);
     _parent.StopFlag = false;
     return newItem;
 }
开发者ID:netintellect,项目名称:NetOffice,代码行数:7,代码来源:AddinItems.cs

示例4: ChatOptions

        public ChatOptions()
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", true);
            m_reg = key.CreateSubKey("TwitchChatClient");

            m_iniReader = new IniReader("options.ini");

            IniSection section = m_iniReader.GetSectionByName("stream");
            if (section == null)
                throw new InvalidOperationException("Options file missing [Stream] section.");

            m_stream = section.GetValue("stream");
            m_user = section.GetValue("twitchname") ?? section.GetValue("user") ?? section.GetValue("username");
            m_oath = section.GetValue("oauth") ?? section.GetValue("pass") ?? section.GetValue("password");

            section = m_iniReader.GetSectionByName("highlight");
            List<string> highlights = new List<string>();
            if (section != null)
                foreach (string line in section.EnumerateRawStrings())
                    highlights.Add(DoReplacements(line.ToLower()));

            m_highlightList = highlights.ToArray();

            section = m_iniReader.GetSectionByName("ignore");
            if (section != null)

            m_ignore = new HashSet<string>((from s in section.EnumerateRawStrings()
                                            where !string.IsNullOrWhiteSpace(s)
                                            select s.ToLower()));
        }
开发者ID:NitroXenon,项目名称:WinterBot,代码行数:30,代码来源:ChatOptions.cs

示例5: PopulateOptions

 // populates an options object from values stored in the registry
 private static void PopulateOptions(object options, RegistryKey key)
 {
     foreach (PropertyInfo propInfo in options.GetType().GetProperties())
     {
         if (propInfo.IsDefined(typeof(ApplyPolicyAttribute)))
         {
             object valueFromRegistry = key.GetValue(propInfo.Name);
             if (valueFromRegistry != null)
             {
                 if (propInfo.PropertyType == typeof(string))
                 {
                     propInfo.SetValue(options, Convert.ToString(valueFromRegistry, CultureInfo.InvariantCulture));
                 }
                 else if (propInfo.PropertyType == typeof(int))
                 {
                     propInfo.SetValue(options, Convert.ToInt32(valueFromRegistry, CultureInfo.InvariantCulture));
                 }
                 else if (propInfo.PropertyType == typeof(Type))
                 {
                     propInfo.SetValue(options, Type.GetType(Convert.ToString(valueFromRegistry, CultureInfo.InvariantCulture), throwOnError: true));
                 }
                 else
                 {
                     throw CryptoUtil.Fail("Unexpected type on property: " + propInfo.Name);
                 }
             }
         }
     }
 }
开发者ID:leloulight,项目名称:DataProtection,代码行数:30,代码来源:RegistryPolicyResolver.cs

示例6: DeleteSubKeyTree

 /// <summary>
 /// Helper function to recursively delete a sub-key (swallows errors in the
 /// case of the sub-key not existing
 /// </summary>
 /// <param name="root">Root to delete key from</param>
 /// <param name="subKey">Name of key to delete</param>
 public static void DeleteSubKeyTree(RegistryKey root, string subKey)
 {
     // delete the specified sub-key if if exists (swallow the error if the
     // sub-key does not exist)
     try { root.DeleteSubKeyTree(subKey); }
     catch (ArgumentException) { }
 }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:13,代码来源:RegistryHelper.cs

示例7: PackageInfo

        internal PackageInfo(RegistryKey key)
        {
            PackageId = Path.GetFileName(key.Name);
            DisplayName = (string)key.GetValue("DisplayName");
            PackageRootFolder = (string)key.GetValue("PackageRootFolder");

            // walk the files...
            XamlFiles = new List<string>();
            JsFiles = new List<string>();
            WalkFiles(new DirectoryInfo(PackageRootFolder));

            // probe for a start page...
            var appKey = key.OpenSubKey("Applications");
            if (appKey != null)
            {
                using (appKey)
                {
                    foreach(var subAppName in appKey.GetSubKeyNames())
                    {
                        using (var subAppKey = appKey.OpenSubKey(subAppName))
                        {
                            if (subAppKey != null)
                            {
                                var start = (string)subAppKey.GetValue("DefaultStartPage");
                                if (!(string.IsNullOrEmpty(start)))
                                {
                                    FoundStartPage = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:ZeroInfinite,项目名称:XamlOrHtml,代码行数:35,代码来源:PackageInfo.cs

示例8: WriteToRegistry

		static public void WriteToRegistry(RegistryKey RegHive, string RegPath, string KeyName, string KeyValue)
		{
			// Split the registry path
			string[] regStrings;
			regStrings = RegPath.Split('\\');
			// First item of array will be the base key, so be carefull iterating below
			RegistryKey[] RegKey = new RegistryKey[regStrings.Length + 1];
			RegKey[0] = RegHive;

			for( int i = 0; i < regStrings.Length; i++ )
			{
				RegKey[i + 1] = RegKey[i].OpenSubKey(regStrings[i], true);
				// If key does not exist, create it
				if (RegKey[i + 1] == null)
				{
					RegKey[i + 1] = RegKey[i].CreateSubKey(regStrings[i]);
				}
			}

			// Write the value to the registry
			try
			{
				RegKey[regStrings.Length].SetValue(KeyName, KeyValue);
			}
			catch (System.NullReferenceException)
			{
				throw(new Exception("Null Reference"));
			}
			catch (System.UnauthorizedAccessException)
			{
				throw(new Exception("Unauthorized Access"));
			}
		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:33,代码来源:RegistryUtil.cs

示例9: GetRegistryStringValue

 public static string GetRegistryStringValue(RegistryKey baseKey, string strSubKey, string strValue)
 {
     object obj = null;
     string text = string.Empty;
     string result;
     try
     {
         RegistryKey registryKey = baseKey.OpenSubKey(strSubKey);
         if (registryKey == null)
         {
             result = null;
             return result;
         }
         obj = registryKey.GetValue(strValue);
         if (obj == null)
         {
             result = null;
             return result;
         }
         registryKey.Close();
         baseKey.Close();
     }
     catch (Exception ex)
     {
         text = ex.Message;
         result = null;
         return result;
     }
     result = obj.ToString();
     return result;
 }
开发者ID:Padungsak,项目名称:efinTradePlus,代码行数:31,代码来源:BusinessServiceFactory.cs

示例10: UninstallerObject

 public UninstallerObject(RegistryKey rootKey, string keyPath, string keyName)
 {
     using (RegistryKey hkKey = rootKey.OpenSubKey(keyPath, false))
     {
         string ApplicationName = hkKey.GetValue("DisplayName") as string;
         if (string.IsNullOrEmpty(ApplicationName))
         {
             ApplicationName = hkKey.GetValue("QuietDisplayName") as string;
         }
         if (string.IsNullOrEmpty(ApplicationName))
             ApplicationName = keyName;
         Objects[(int)UninstallerItemTypes.Application] = ApplicationName;
         Objects[(int)UninstallerItemTypes.Path] = hkKey.GetValue("InstallLocation") as string;
         Objects[(int)UninstallerItemTypes.Key] = keyName;
         Objects[(int)UninstallerItemTypes.Version] = hkKey.GetValue("DisplayVersion") as string;
         Objects[(int)UninstallerItemTypes.Publisher] = hkKey.GetValue("Publisher") as string;
         Objects[(int)UninstallerItemTypes.HelpLink] = hkKey.GetValue("HelpLink") as string;
         Objects[(int)UninstallerItemTypes.AboutLink] = hkKey.GetValue("URLInfoAbout") as string;
         ToolTipText = hkKey.GetValue("UninstallString") as string;
         Objects[(int)UninstallerItemTypes.Action] = ToolTipText;
         if (string.IsNullOrEmpty(ToolTipText))
         {
             ForegroundColor = Color.Gray;
         }
         else if (!string.IsNullOrEmpty(Path))
         {
             ForegroundColor = Color.Blue;
         }
     }
 }
开发者ID:zippy1981,项目名称:GTools,代码行数:30,代码来源:UninstallerObject.cs

示例11: CopyFromRegistry

 public void CopyFromRegistry(RegistryKey keyToSave)
 {
     if (keyToSave == null)
     {
         throw new ArgumentNullException("keyToSave");
     }
     this.ValueNames = keyToSave.GetValueNames();
     if (this.ValueNames == null)
     {
         this.ValueNames = new string[0];
     }
     this.Values = new object[this.ValueNames.Length];
     for (int i = 0; i < this.ValueNames.Length; i++)
     {
         this.Values[i] = keyToSave.GetValue(this.ValueNames[i]);
     }
     this.KeyNames = keyToSave.GetSubKeyNames();
     if (this.KeyNames == null)
     {
         this.KeyNames = new string[0];
     }
     this.Keys = new SerializableRegistryKey[this.KeyNames.Length];
     for (int j = 0; j < this.KeyNames.Length; j++)
     {
         this.Keys[j] = new SerializableRegistryKey(keyToSave.OpenSubKey(this.KeyNames[j]));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:SerializableRegistryKey.cs

示例12: GetSubKey

 /// <summary>
 /// 获取注册表项的子节点,并将其添加到树形控件节点中
 /// </summary>
 /// <param name="nodes"></param>
 /// <param name="rootKey"></param>
 public void GetSubKey(TreeNodeCollection nodes, RegistryKey rootKey)
 {
     if (nodes.Count != 0) return;
     //获取项的子项名称列表
     string[] keyNames = rootKey.GetSubKeyNames();
     //遍历子项名称
     foreach (string keyName in keyNames)
     {
     try
     {
     //根据子项名称功能注册表项
     RegistryKey key = rootKey.OpenSubKey(keyName);
     //如果表项不存在,则继续遍历下一表项
     if (key == null) continue;
     //根据子项名称创建对应树形控件节点
     TreeNode TNRoot = new TreeNode(keyName);
     //将注册表项与树形控件节点绑定在一起
     TNRoot.Tag = key;
     //向树形控件中添加节点
     nodes.Add(TNRoot);
     }
     catch
     {
     //如果由于权限问题无法访问子项,则继续搜索下一子项
     continue;
     }
     }
 }
开发者ID:dalinhuang,项目名称:wdeqawes-efrwserd-rgtedrtf,代码行数:33,代码来源:FormExplorer.cs

示例13: UninstallerDataObject

 public UninstallerDataObject(RegistryKey rootKey, string keyPath, string keyName)
     : base(keyName)
 {
     BasedInLocalMachine = (rootKey == Registry.LocalMachine);
     Refresh(rootKey, keyPath, keyName);
     ConstructionIsFinished = true;
 }
开发者ID:johnhk,项目名称:pserv4,代码行数:7,代码来源:UninstallerDataObject.cs

示例14: IsApplicationInKey

 private static bool IsApplicationInKey(RegistryKey key, string applicationName)
 {
     return key.GetSubKeyNames()
         .Select(key.OpenSubKey)
         .Select(subkey => subkey.GetValue("DisplayName") as string)
         .Any(displayName => displayName != null && displayName.Contains(applicationName));
 }
开发者ID:dineshkummarc,项目名称:Espera,代码行数:7,代码来源:RegistryHelper.cs

示例15: GetDotNetVersion

        /// <summary>
        /// Get framework version for specified SubKey
        /// </summary>
        /// <param name="parentKey"></param>
        /// <param name="subVersionName"></param>
        /// <param name="versions"></param>
        private static void GetDotNetVersion(RegistryKey parentKey, string subVersionName, IList<NetFrameworkVersionInfo> versions)
        {
            if (parentKey != null)
            {
                string installed = Convert.ToString(parentKey.GetValue("Install"));

                if (installed == "1")
                {
                    NetFrameworkVersionInfo versionInfo = new NetFrameworkVersionInfo();

                    versionInfo.VersionString = Convert.ToString(parentKey.GetValue("Version"));

                    var test = versionInfo.BaseVersion;

                    versionInfo.InstallPath = Convert.ToString(parentKey.GetValue("InstallPath"));
                    versionInfo.ServicePackLevel = Convert.ToInt32(parentKey.GetValue("SP"));

                    if (parentKey.Name.Contains("Client"))
                        versionInfo.FrameworkProfile = "Client Profile";
                    else if (parentKey.Name.Contains("Full"))
                        versionInfo.FrameworkProfile = "Full Profile";

                    if (!versions.Contains(versionInfo))
                        versions.Add(versionInfo);
                }
            }
        }
开发者ID:steve600,项目名称:VersatileMediaManager,代码行数:33,代码来源:DotNetFrameworkInfo.cs


注:本文中的Microsoft.Win32.RegistryKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。