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


C# RegistryKey.OpenSubKey方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: PrintFileTypes

        public void PrintFileTypes( RegistryKey root )
        {
            if( root == null ) return;
            string[] subkeys = root.GetSubKeyNames();
            foreach( string subname in subkeys )
            {
                // For each key, if it starts with . then it's a file type.
                // Otherwise, ignore it.
                if( subname == null ) continue;
                if( !subname.StartsWith(".") ) continue;

                // Open the key and find its default value.
                // If no default, skip this key, since it effectively
                // doesn't have an assigned type.
                RegistryKey subkey = root.OpenSubKey( subname );
                if( subkey == null ) continue;
                string typename = (string) subkey.GetValue( "" );
                if( typename == null ) continue; // No default value

                // If it has a value "Content Type", that's the mime type.
                string mimetype = null;
                mimetype = (string) subkey.GetValue( "Content Type" );

                // Find the descriptor type.
                RegistryKey typekey = root.OpenSubKey( typename );
                if( typekey == null ) continue;
                string displayName = (string) typekey.GetValue( "" );

                // Find the default icon.
                RegistryKey iconkey = typekey.OpenSubKey( "DefaultIcon" );
                if( iconkey == null ) continue;
                string iconname = (string) iconkey.GetValue( "" );

                // Split the icon descriptor to get the path and the resource ID.
                char[] separators = new char[1];
                separators[0] = ',';
                string[] iconparts = null;
                if( iconname != null )
                    iconparts = iconname.Split( separators );

                string iconfile = "";
                string iconres = "";
                if( iconparts != null && iconparts.Length <= 2 )
                {
                    iconfile = iconparts[0];
                    if( iconparts.Length == 2 ) iconres = iconparts[1];
                }

                Console.WriteLine( "Extension:      "+subname );
                Console.WriteLine( "  Type:         "+typename );
                Console.WriteLine( "  MimeType:     "+mimetype );
                Console.WriteLine( "  DisplayName:  "+displayName );
                Console.WriteLine( "  IconDesc:     "+iconname );

                // Needs checking.
                //Console.WriteLine( "  Icon:         "+iconfile );
                //Console.WriteLine( "  IconResource: "+iconres );
                Console.WriteLine( "" );
            }
        }
开发者ID:neechbear,项目名称:Apache2-AutoIndex-XSLT,代码行数:60,代码来源:RegFileTypes.cs

示例9: Test04

        public void Test04()
        {
            // [] Give subkey a value and then delete tree

            _rk1 = Microsoft.Win32.Registry.CurrentUser;
            _rk1.CreateSubKey(_testKeyName);
            if (_rk1.OpenSubKey(_testKeyName) == null)
            {
                Assert.False(true, "Error Could not get subkey");
            }
            _rk1.DeleteSubKeyTree(_testKeyName);
            if (_rk1.OpenSubKey(_testKeyName) != null)
            {
                Assert.False(true, "Error SubKey still there");
            }

            // CreateSubKey should just open a SubKeyIfIt already exists
            _rk2 = _rk1.CreateSubKey(_testKeyName);
            _rk2.CreateSubKey("BLAH");
            
            if (_rk1.OpenSubKey(_testKeyName).OpenSubKey("BLAH") == null)
            {
                Assert.False(true, "Error Expected get not returned");
            }
            _rk2.DeleteSubKey("BLAH");
            if (_rk2.OpenSubKey("BLAH") != null)
            {
                Assert.False(true, "Error SubKey was not deleted");
            }
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:30,代码来源:RegistryKey_DeleteSubKeyTree_str.cs

示例10: DetectJavaFromRegistry

		private static void DetectJavaFromRegistry(RegistryKey rootkey, bool is64Bit = false)
		{
			RegistryKey javaJre = rootkey.OpenSubKey("Java Runtime Environment");
			RegistryKey javaJdk = rootkey.OpenSubKey("Java Development Kit");

			foreach (RegistryKey versionRoot in new[] {javaJre, javaJdk})
			{
				if (versionRoot == null || versionRoot.GetSubKeyNames().Length < 1) continue; // no keys in here

				foreach (string subkey in versionRoot.GetSubKeyNames())
				{
					Match r = Regex.Match(subkey, @"^\d.(\d)$");
					if (r.Success)
					{
						int runtimeversion = Convert.ToInt32(r.Groups[1].Value);
						RegistryKey subKeyInstance = versionRoot.OpenSubKey(subkey);
						if (subKeyInstance != null)
						{
							if (string.IsNullOrEmpty(subKeyInstance.GetValue("JavaHome").ToString())) continue;
							string path = subKeyInstance.GetValue("JavaHome") + "\\bin\\java.exe";
							SetJavaPath(runtimeversion, is64Bit, path);
						}
					}
				}
			}
		}
开发者ID:CaptainTF,项目名称:bukkitgui2,代码行数:26,代码来源:JavaApi.cs

示例11: executeAction

		public override void executeAction(actionBase Action) {
			var action = (removeRegistryKeyAction) Action;

			RegistryKey rootKey = getRegistryRoot(action.rootHive);
			m_rootKey = rootKey;

			//Erstelle ein Backup des Registryschlüssels einschl. aller Unterschlüssel
			getSubKeys(m_removedKeys, rootKey, action.Path);
			//Sichere Registrywerte in dem Rootschlüssel
			m_removedKeys.Add(action.Path);
			onProgressChanged(Language.GetString("applyRemoveRegistryKeyAction_progressStep_1"), 30);
			foreach (string baseRegVal in rootKey.OpenSubKey(action.Path).GetValueNames()) {
				m_removedValues.Add(new rollbackRegistryItem(action.Path, baseRegVal,
				                                             rootKey.OpenSubKey(action.Path).GetValue(baseRegVal),
				                                             rootKey.OpenSubKey(action.Path).GetValueKind(baseRegVal)));
			}
			//Sichere Registrywerte in allen Unterschlüsseln
			onProgressChanged(Language.GetString("applyRemoveRegistryKeyAction_progressStep_2"), 60);
			foreach (string Item in m_removedKeys) {
				foreach (string regVal in rootKey.OpenSubKey(Item).GetValueNames()) {
					m_removedValues.Add(new rollbackRegistryItem(Item, regVal, m_rootKey.OpenSubKey(Item).GetValue(regVal),
					                                             m_rootKey.OpenSubKey(Item).GetValueKind(regVal)));
				}
			}

			//Registryschlüssel löschen
			onProgressChanged(
				string.Format(Language.GetString("applyRemoveRegistryKeyAction_progressStep_3"), rootKey, action.Path), 100);
			rootKey.DeleteSubKeyTree(action.Path);
		}
开发者ID:hbaes,项目名称:updateSystem.NET,代码行数:30,代码来源:applyRemoveRegistryKeyAction.cs

示例12: FindSubKey

        protected RegistryKey FindSubKey(RegistryKey parent, string name)
        {
            RegistryKey key = parent.OpenSubKey(name);
            if (key != null) return key;

            name = name.ToUpper();

            List<RegistryKey> levelList = new List<RegistryKey>(100);

            string[] subKeys = parent.GetSubKeyNames();
            if (subKeys == null || subKeys.Length == 0)
            {
                return null;
            }
            foreach (string sub in subKeys)
            {
                RegistryKey k = null;
                try
                {
                    k = parent.OpenSubKey(sub);
                }
                catch (System.Security.SecurityException) { continue; }

                if (k == null) continue;
                levelList.Add(k);

                if (k.Name.ToUpper() == name)
                {
                    return k;
                }
            }
            //广度优先
            while (true)
            {
                if (levelList == null || levelList.Count == 0) break;

                List<RegistryKey> list = new List<RegistryKey>(levelList.Count);
                foreach (RegistryKey k in levelList)
                {
                    string[] subs = k.GetSubKeyNames();
                    foreach (string s in subs)
                    {
                        RegistryKey sk = null;
                        try
                        {
                            sk = k.OpenSubKey(s);
                        }
                        catch (System.Security.SecurityException) { continue; }

                        if (sk == null) continue;
                        if (s.ToUpper() == name) return sk;
                        list.Add(sk);
                    }
                }
                levelList = list;
            }

            return null;
        }
开发者ID:howbigbobo,项目名称:DailyCode,代码行数:59,代码来源:IOracleInfo.cs

示例13: SetUp

 private static void SetUp()
 {
     Key = Registry.CurrentUser.OpenSubKey("SOFTWARE", true);
     RegistryKey k = Key.OpenSubKey("OsuMirror", true);
     if (k == null)
     {
         Key.CreateSubKey("OsuMirror");
         Key = Key.OpenSubKey("OsuMirror", true);
     }
 }
开发者ID:RagingCactus,项目名称:osu-mirror,代码行数:10,代码来源:Registry.cs

示例14: TestInitialize

 public void TestInitialize()
 {
     _rk = Registry.CurrentUser.OpenSubKey("Software", true);
     if (_rk.OpenSubKey(_testKeyName) != null)
         _rk.DeleteSubKeyTree(_testKeyName);
     if (_rk.OpenSubKey(_testVolatileKeyName) != null)
         _rk.DeleteSubKeyTree(_testVolatileKeyName);
     if (_rk.OpenSubKey(_testNonVolatileKeyName) != null)
         _rk.DeleteSubKeyTree(_testNonVolatileKeyName);
     if (_rk.OpenSubKey(_testRegularKey) != null)
         _rk.DeleteSubKeyTree(_testRegularKey);
 }
开发者ID:gitter-badger,项目名称:corefx,代码行数:12,代码来源:RegistryKeyTypes.cs

示例15: TestInitialize

 public void TestInitialize()
 {
     var counter = Interlocked.Increment(ref s_keyCount);
     _madeUpKey = _madeUpKey + counter.ToString();
     _rk = Registry.CurrentUser.OpenSubKey("Software", true);
     if (_rk.OpenSubKey(_madeUpKey) != null)
         _rk.DeleteSubKeyTree(_madeUpKey);
     if (_rk.OpenSubKey(_subKeyExists) != null)
         _rk.DeleteSubKeyTree(_subKeyExists);
     if (_rk.OpenSubKey(_subKeyExists2) != null)
         _rk.DeleteSubKeyTree(_subKeyExists2);
 }
开发者ID:gitter-badger,项目名称:corefx,代码行数:12,代码来源:RegistryKey_DeleteSubKeyTree.cs


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