internal StartupEntry(StartupPointData dataPoint, string fileName, string targetString)
        {
            AllUsersStore   = dataPoint.AllUsers;
            IsRegKey        = dataPoint.IsRegKey;
            IsRunOnce       = dataPoint.IsRunOnce;
            EntryLongName   = fileName;
            ParentShortName = dataPoint.Name;
            ParentLongName  = dataPoint.Path.TrimEnd('\\');

            Command = targetString;

            CommandFilePath = ProcessCommandString(Command);

            if (CommandFilePath == null)
            {
                throw new ArgumentException("Failed to extract program path from supplied information");
            }

            FillInformationFromFile(CommandFilePath);

            if (!string.IsNullOrEmpty(EntryLongName))
            {
                ProgramName = IsRegKey ? EntryLongName : Path.GetFileNameWithoutExtension(EntryLongName);
            }

            if (string.IsNullOrEmpty(ProgramName))
            {
                ProgramName = ProgramNameTrimmed;
            }
        }
        /// <summary>
        ///     Look for registry values in the run keys
        /// </summary>
        private static IEnumerable <StartupEntry> GetRegStartupItems(StartupPointData point)
        {
            var results = new List <StartupEntry>();

            try
            {
                using (var rKey = RegistryTools.OpenRegistryKey(point.Path))
                {
                    if (rKey != null)
                    {
                        results.AddRange(from name in rKey.GetValueNames()
                                         let result = rKey.GetValue(name) as string
                                                      where !string.IsNullOrEmpty(result)
                                                      select new StartupEntry(point, name, result));
                    }
                }
            }
            catch (ArgumentException)
            {
                // Key doesn't exist, create it
                RegistryTools.CreateSubKeyRecursively(point.Path)?.Close();
            }

            return(results);
        }
        /// <summary>
        ///     Look for registry values in the run keys
        /// </summary>
        private static IEnumerable <StartupEntry> GetRegStartupItems(StartupPointData point)
        {
            var results = new List <StartupEntry>();

            try
            {
                using (var rKey = RegistryTools.OpenRegistryKey(point.Path))
                {
                    if (rKey != null)
                    {
                        foreach (var name in rKey.GetValueNames())
                        {
                            var result = rKey.GetStringSafe(name);
                            if (string.IsNullOrEmpty(result))
                            {
                                continue;
                            }

                            try
                            {
                                results.Add(new StartupEntry(point, name, result));
                            }
                            catch (Exception ex)
                            {
                                PremadeDialogs.GenericError(ex);
                            }
                        }
                    }
                }
            }
            catch (ArgumentException)
            {
                // Key doesn't exist, create it
                RegistryTools.CreateSubKeyRecursively(point.Path)?.Close();
            }
            catch (SecurityException ex)
            {
                Console.WriteLine(@"Failed to process startup entries: " + ex);
            }

            return(results);
        }
예제 #4
0
        internal StartupEntry(StartupPointData dataPoint, string fileName, string targetString)
        {
            AllUsersStore   = dataPoint.AllUsers;
            IsRegKey        = dataPoint.IsRegKey;
            IsRunOnce       = dataPoint.IsRunOnce;
            EntryLongName   = fileName;
            ParentShortName = dataPoint.Name;
            ParentLongName  = dataPoint.Path?.TrimEnd('\\');

            Command = targetString ?? string.Empty;

            if (!string.IsNullOrEmpty(EntryLongName))
            {
                ProgramName = IsRegKey ? EntryLongName : Path.GetFileNameWithoutExtension(EntryLongName);
            }

            if (!string.IsNullOrEmpty(targetString))
            {
                CommandFilePath = ProcessCommandString(Command);

                if (CommandFilePath != null)
                {
                    FillInformationFromFile(CommandFilePath);
                }

                if (string.IsNullOrEmpty(ProgramName))
                {
                    ProgramName = ProgramNameTrimmed;
                }
            }

            if (string.IsNullOrEmpty(ProgramName))
            {
                ProgramName = targetString ?? dataPoint.Name ?? CommonStrings.Unknown;
            }
            if (string.IsNullOrEmpty(ProgramNameTrimmed))
            {
                ProgramNameTrimmed = StringTools.StripStringFromVersionNumber(ProgramName);
            }
        }
        /// <summary>
        ///     Look for links in startup folders
        /// </summary>
        private static IEnumerable <StartupEntry> GetDriveStartupItems(StartupPointData point)
        {
            if (!Directory.Exists(point.Path))
            {
                yield break;
            }

            foreach (var name in Directory.GetFiles(point.Path)
                     .Where(name => ".lnk".Equals(Path.GetExtension(name), StringComparison.CurrentCultureIgnoreCase)))
            {
                string target;
                try
                {
                    target = WindowsTools.ResolveShortcut(name);
                }
                catch
                {
                    target = string.Empty;
                }
                yield return(new StartupEntry(point, Path.GetFileName(name), target));
            }
        }
        /// <summary>
        ///     Look for links in startup folders
        /// </summary>
        private static IEnumerable <StartupEntry> GetDriveStartupItems(StartupPointData point)
        {
            if (!Directory.Exists(point.Path))
            {
                yield break;
            }

            foreach (var name in Directory.GetFiles(point.Path)
                     .Where(name => ".lnk".Equals(Path.GetExtension(name), StringComparison.CurrentCultureIgnoreCase)))
            {
                StartupEntry result;
                try
                {
                    result = new StartupEntry(point, Path.GetFileName(name), WindowsTools.ResolveShortcut(name));
                }
                catch (Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                    continue;
                }
                yield return(result);
            }
        }