Esempio n. 1
0
        internal static AutostartProgramInfo CompleteAutostartProgramInfo(AutostartProgramInfo autostartProgramInfo)
        {
            FileInfo fileInfo = null;

            try
            {
                fileInfo =
                    new FileInfo(autostartProgramInfo.CommandLine.Contains("\"")
                        ? autostartProgramInfo.CommandLine.Split(new[] { '"' }, StringSplitOptions.RemoveEmptyEntries)[0]
                                 //if there are quotes, they should contain the full path
                        : Regex.Match(autostartProgramInfo.CommandLine, @"^[^\/]+?(\.... |\z)").Value);
                //Match everything until / or an extension (e. g. .exe, .scr, .com) or end of line

                if (!fileInfo.Exists)
                {
                    autostartProgramInfo.EntryStatus = EntryStatus.FileNotFound;
                }
                else
                {
                    autostartProgramInfo.Filename = fileInfo.FullName;
                }
            }
            catch (Exception)
            {
                autostartProgramInfo.EntryStatus = EntryStatus.FileNotFound;
            }

            if (fileInfo?.Exists == true)
            {
                try
                {
                    autostartProgramInfo.Icon = FileUtilities.GetIconFromProcess(fileInfo.FullName);
                }
                catch (Exception)
                {
                    // happens, not that important
                }

                try
                {
                    var fileVersionInfo = FileVersionInfo.GetVersionInfo(fileInfo.FullName);
                    autostartProgramInfo.Publisher   = fileVersionInfo.CompanyName;
                    autostartProgramInfo.Description = fileVersionInfo.FileDescription;

                    if (string.IsNullOrEmpty(autostartProgramInfo.Publisher) &&
                        string.IsNullOrEmpty(autostartProgramInfo.Description))
                    {
                        autostartProgramInfo.EntryStatus = EntryStatus.NoDescriptionOrCompany;
                    }
                }
                catch (Exception)
                {
                    autostartProgramInfo.EntryStatus = EntryStatus.NoDescriptionOrCompany;
                }
            }

            return(autostartProgramInfo);
        }
Esempio n. 2
0
        public void RemoveAutostartEntry(AutostartProgramInfo autostartProgramInfo)
        {
            var nameData = Encoding.UTF8.GetBytes(autostartProgramInfo.Name);
            var data     = new byte[nameData.Length + 3];

            data[0] = (byte)StartupManagerCommunication.RemoveAutostartEntry;
            data[1] = (byte)(autostartProgramInfo.IsEnabled ? 1 : 0);
            data[2] = (byte)autostartProgramInfo.AutostartLocation;
            Array.Copy(nameData, 0, data, 3, nameData.Length);
            ConnectionInfo.SendCommand(this, data);
            LogService.Send(string.Format((string)Application.Current.Resources["RemoveAutostartEntry"],
                                          autostartProgramInfo.Name));
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public void ChangeAutostartEntry(AutostartProgramInfo autostartProgramInfo, bool enable)
        {
            var nameData = Encoding.UTF8.GetBytes(autostartProgramInfo.Name);
            var data     = new byte[nameData.Length + 2];

            data[0] =
                (byte)
                (enable
                        ? StartupManagerCommunication.EnableAutostartEntry
                        : StartupManagerCommunication.DisableAutostartEntry);
            data[1] = (byte)autostartProgramInfo.AutostartLocation;
            Array.Copy(nameData, 0, data, 2, nameData.Length);
            ConnectionInfo.SendCommand(this, data);
            LogService.Send(
                string.Format(
                    enable
                        ? (string)Application.Current.Resources["EnableAutostartEntry"]
                        : (string)Application.Current.Resources["DisableAutostartEntry"], autostartProgramInfo.Name));
        }
Esempio n. 5
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);
        }