Exemplo n.º 1
0
        public static List <AutostartProgramInfo> GetAutostartProgramsFromFolder(AutostartLocation autostartLocation, bool isEnabled)
        {
            var result = new List <AutostartProgramInfo>();

            try
            {
                var directory = GetDirectoryFromAutostartLocation(autostartLocation, isEnabled);
                if (directory.Exists)
                {
                    foreach (var fileInfo in directory.GetFiles())
                    {
                        if (fileInfo.Name == "desktop.ini")
                        {
                            continue;
                        }

                        FileInfo file;
                        if (fileInfo.Extension == ".lnk")
                        {
                            file = new FileInfo(GetShortcutTarget(fileInfo.FullName));
                        }
                        else
                        {
                            file = fileInfo;
                        }

                        var entry = new AutostartProgramInfo
                        {
                            Name              = fileInfo.Name, //This should be fileinfo
                            CommandLine       = file.FullName,
                            IsEnabled         = isEnabled,
                            AutostartLocation = autostartLocation
                        };

                        result.Add(AutostartManager.CompleteAutostartProgramInfo(entry));
                    }
                }
            }
            catch (Exception)
            {
                // ignored
            }

            return(result);
        }
Exemplo n.º 2
0
        public static List <AutostartProgramInfo> GetAutostartProgramsFromRegistryKey(
            AutostartLocation autostartLocation, bool isEnabled)
        {
            var result = new List <AutostartProgramInfo>();

            try
            {
                using (var registryKey = GetRegistryKeyFromAutostartLocation(autostartLocation, isEnabled, false))
                {
                    if (registryKey != null)
                    {
                        foreach (var valueName in registryKey.GetValueNames())
                        {
                            var value = registryKey.GetValue(valueName) as string;
                            if (value == null)
                            {
                                continue;
                            }

                            var entry = new AutostartProgramInfo
                            {
                                Name              = valueName,
                                CommandLine       = value,
                                IsEnabled         = isEnabled,
                                AutostartLocation = autostartLocation
                            };

                            result.Add(AutostartManager.CompleteAutostartProgramInfo(entry));
                        }
                    }
                }
            }
            catch (Exception)
            {
                // ignored
            }

            return(result);
        }