GetValueNames() private method

private GetValueNames ( [ root, [ key ) : string[]
root [
key [
return string[]
Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves a list of file associations and programmatic identifiers the registry.
        /// </summary>
        private static (ComparableTuple <string>[] fileAssocs, string[] progIDs) GetFileAssocData()
        {
            var fileAssocsList = new List <ComparableTuple <string> >();
            var progIDsList    = new List <string>();

            foreach (string keyName in Registry.ClassesRoot.GetSubKeyNames())
            {
                if (keyName.StartsWith("."))
                {
                    using var assocKey = Registry.ClassesRoot.OpenSubKey(keyName);
                    // Get the main ProgID
                    string assocValue = assocKey?.GetValue("")?.ToString();
                    if (string.IsNullOrEmpty(assocValue))
                    {
                        continue;
                    }
                    fileAssocsList.Add(new ComparableTuple <string>(keyName, assocValue));

                    // Get additional ProgIDs
                    fileAssocsList.AddRange(RegUtils.GetValueNames(assocKey, FileType.RegSubKeyOpenWith).Select(progID => new ComparableTuple <string>(keyName, progID)));
                }
                else
                {
                    progIDsList.Add(keyName);
                }
            }

            return(fileAssocsList.ToArray(), progIDsList.ToArray());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves a list of file assocations and programatic indentifiers the registry.
        /// </summary>
        private static void GetFileAssocData(out ComparableTuple <string>[] fileAssocs, out string[] progIDs)
        {
            var fileAssocsList = new List <ComparableTuple <string> >();
            var progIDsList    = new List <string>();

            foreach (string keyName in Registry.ClassesRoot.GetSubKeyNames())
            {
                if (keyName.StartsWith("."))
                {
                    using (var assocKey = Registry.ClassesRoot.OpenSubKey(keyName))
                    {
                        if (assocKey == null)
                        {
                            continue;
                        }

                        // Get the main ProgID
                        fileAssocsList.Add(new ComparableTuple <string>(keyName, assocKey.GetValue("", "").ToString()));

                        // Get additional ProgIDs
                        fileAssocsList.AddRange(RegUtils.GetValueNames(assocKey, FileType.RegSubKeyOpenWith).Select(progID => new ComparableTuple <string>(keyName, progID)));
                    }
                }
                else
                {
                    progIDsList.Add(keyName);
                }
            }

            fileAssocs = fileAssocsList.ToArray();
            progIDs    = progIDsList.ToArray();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves a list of AutoPlay associations from the registry.
        /// </summary>
        /// <param name="hive">The registry hive to search in (usually HKCU or HKLM).</param>
        /// <exception cref="IOException">There was an error accessing the registry.</exception>
        /// <exception cref="UnauthorizedAccessException">Read access to the registry was not permitted.</exception>
        private static ComparableTuple <string>[] GetAutoPlayAssocs(RegistryKey hive)
        {
            using var eventsKey = hive.OpenSubKey(AutoPlay.RegKeyAssocs);
            if (eventsKey == null)
            {
                return(new ComparableTuple <string> [0]);
            }

            return((
                       from eventName in eventsKey.GetSubKeyNames()
                       from handlerName in RegUtils.GetValueNames(eventsKey, eventName)
                       select new ComparableTuple <string>(eventName, handlerName)).ToArray());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Stores information about the current state of the registry in a snapshot.
        /// </summary>
        /// <exception cref="IOException">There was an error accessing the registry.</exception>
        /// <exception cref="UnauthorizedAccessException">Read access to the registry was not permitted.</exception>
        private void TakeRegistry()
        {
            ServiceAssocs           = GetServiceAssocs();
            AutoPlayHandlersUser    = RegUtils.GetSubKeyNames(Registry.CurrentUser, AutoPlay.RegKeyHandlers);
            AutoPlayHandlersMachine = RegUtils.GetSubKeyNames(Registry.LocalMachine, AutoPlay.RegKeyHandlers);
            AutoPlayAssocsUser      = GetAutoPlayAssocs(Registry.CurrentUser);
            AutoPlayAssocsMachine   = GetAutoPlayAssocs(Registry.LocalMachine);
            (FileAssocs, ProgIDs)   = GetFileAssocData();
            ProtocolAssocs          = GetProtocolAssoc();
            ClassIDs = RegUtils.GetSubKeyNames(Registry.ClassesRoot, ComServer.RegKeyClassesIDs);
            RegisteredApplications = RegUtils.GetValueNames(Registry.LocalMachine, AppRegistration.RegKeyMachineRegisteredApplications);

            ContextMenuFiles           = RegUtils.GetSubKeyNames(Registry.ClassesRoot, ContextMenu.RegKeyClassesFiles + @"\shell");
            ContextMenuExecutableFiles = RegUtils.GetSubKeyNames(Registry.ClassesRoot, ContextMenu.RegKeyClassesExecutableFiles + @"\shell");
            ContextMenuDirectories     = RegUtils.GetSubKeyNames(Registry.ClassesRoot, ContextMenu.RegKeyClassesDirectories + @"\shell");
            ContextMenuAll             = RegUtils.GetSubKeyNames(Registry.ClassesRoot, ContextMenu.RegKeyClassesAll + @"\shell");
        }