예제 #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);
        }
예제 #2
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;
        }