예제 #1
0
        public void RegistryKeyInfoTest()
        {
            const string pathToKey   = @"HKEY_CURRENT_USER\Any\Path";
            var          registryKey = new RegistryKeyInfo(pathToKey);

            Assert.AreEqual(registryKey.Hive, RegistryHive.CurrentUser);
            Assert.AreEqual(registryKey.PathToKey, @"Any\Path");
        }
예제 #2
0
        public static Optional <RegistryKey> OpenRegistryKey(RegistryKeyInfo registryKeyInfo, bool forceKey = false)
        {
            var baseKey = RegistryKey.OpenBaseKey(registryKeyInfo.Hive, RegistryView.Default);
            var aRegKey = registryKeyInfo.PathToKey;

            return(forceKey
        ? Optional <RegistryKey> .Of(baseKey.CreateSubKey(aRegKey))
        : Optional <RegistryKey> .OfNullable(baseKey.OpenSubKey(aRegKey)));
        }
예제 #3
0
        public static RegistryKey OpenParent(this RegistryKey registryKey)
        {
            var pathToRegKey  = registryKey.Name;
            var lastSep       = pathToRegKey.LastIndexOf('\\');
            var pathToParent  = pathToRegKey.Substring(0, lastSep);
            var keyInfoParent = new RegistryKeyInfo(pathToParent);

            return(OpenRegistryKey(keyInfoParent).Value);
        }
예제 #4
0
        /// <summary>
        /// Opens a RegistryKey from a path "<RegistryHive>\path\to\key". I.e. "HKEY_CURRENT_USER\Software\Microsoft"
        /// </summary>
        /// <param name="pathToKey"></param>
        /// <param name="forceKey"></param>
        /// <returns></returns>
        public static Optional <RegistryKey> OpenRegistryKey(string pathToKey, bool forceKey = false)
        {
            var registryKeyInfo = new RegistryKeyInfo(pathToKey);

            return(OpenRegistryKey(registryKeyInfo, forceKey));
        }