Esempio n. 1
0
        /// <summary>
        ///     Enumerates all subkeys, retrieving both their name and class at the same time.
        /// </summary>
        /// <returns>Names and classes of all the subkeys.</returns>
        public SubKeyContainer[] EnumerateSubKeys()
        {
            SubKeyContainer[] results = new SubKeyContainer[_metadata.SubKeysCount];

            for (uint item = 0; item < _metadata.SubKeysCount; item++)
            {
                uint sizeName  = _metadata.MaxSubKeyLen + 1;
                uint sizeClass = _metadata.MaxClassLen + 1;

                StringBuilder sbName   = new StringBuilder((int)sizeName);
                StringBuilder sbClass  = new StringBuilder((int)sizeClass);
                FILETIME      fileTime = new FILETIME();

                Win32Result result = OffregNative.EnumKey(_intPtr, item, sbName, ref sizeName, sbClass, ref sizeClass,
                                                          ref fileTime);

                if (result != Win32Result.ERROR_SUCCESS)
                {
                    throw new Win32Exception((int)result);
                }

                SubKeyContainer container = new SubKeyContainer();

                container.Name          = sbName.ToString();
                container.Class         = sbClass.ToString();
                container.LastWriteTime = fileTime;

                results[item] = container;
            }

            return(results);
        }
Esempio n. 2
0
        /// <summary>
        ///     Enumerates all subkeys, only retrieving their names.
        /// </summary>
        /// <returns>Names of all the subkeys.</returns>
        public string[] GetSubKeyNames()
        {
            string[] results = new string[_metadata.SubKeysCount];

            for (uint item = 0; item < _metadata.SubKeysCount; item++)
            {
                uint sizeName = _metadata.MaxSubKeyLen + 1;

                StringBuilder sbName = new StringBuilder((int)sizeName);
                Win32Result   result = OffregNative.EnumKey(_intPtr, item, sbName, ref sizeName, null, IntPtr.Zero,
                                                            IntPtr.Zero);

                if (result != Win32Result.ERROR_SUCCESS)
                {
                    throw new Win32Exception((int)result);
                }

                results[item] = sbName.ToString();
            }

            return(results);
        }