Esempio 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);
        }
Esempio 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);
        }
Esempio n. 3
0
        public override void ProcessCommand(byte[] parameter, IConnectionInfo connectionInfo)
        {
            byte[] data;
            switch ((StartupManagerCommunication)parameter[0])
            {
            case StartupManagerCommunication.GetAutostartEntries:
                ResponseBytes((byte)StartupManagerCommunication.ResponseAutostartEntries,
                              new Serializer(typeof(List <AutostartProgramInfo>)).Serialize(
                                  AutostartManager.GetAllAutostartPrograms()),
                              connectionInfo);
                break;

            case StartupManagerCommunication.EnableAutostartEntry:
                try
                {
                    AutostartManager.ChangeAutostartEntry((AutostartLocation)parameter[1],
                                                          Encoding.UTF8.GetString(parameter, 2, parameter.Length - 2), true);
                }
                catch (Exception ex)
                {
                    if (!(ex is SecurityException) && !(ex is UnauthorizedAccessException))
                    {
                        throw;
                    }
                    data    = new byte[parameter.Length];
                    data[0] = (byte)StartupManagerCommunication.ResponseAutostartChangingFailed;
                    Array.Copy(parameter, 1, data, 1, parameter.Length - 1);
                    connectionInfo.CommandResponse(this, data);
                    return;
                }
                data    = new byte[parameter.Length];
                data[0] = (byte)StartupManagerCommunication.ResponseAutostartEntryEnabled;
                Array.Copy(parameter, 1, data, 1, parameter.Length - 1);
                connectionInfo.CommandResponse(this, data);
                break;

            case StartupManagerCommunication.DisableAutostartEntry:
                try
                {
                    AutostartManager.ChangeAutostartEntry((AutostartLocation)parameter[1],
                                                          Encoding.UTF8.GetString(parameter, 2, parameter.Length - 2), false);
                }
                catch (Exception ex)
                {
                    if (!(ex is SecurityException) && !(ex is UnauthorizedAccessException))
                    {
                        throw;
                    }

                    data    = new byte[parameter.Length];
                    data[0] = (byte)StartupManagerCommunication.ResponseAutostartChangingFailed;
                    Array.Copy(parameter, 1, data, 1, parameter.Length - 1);
                    connectionInfo.CommandResponse(this, data);
                    return;
                }
                data    = new byte[parameter.Length];
                data[0] = (byte)StartupManagerCommunication.ResponseAutostartEntryDisabled;
                Array.Copy(parameter, 1, data, 1, parameter.Length - 1);
                connectionInfo.CommandResponse(this, data);
                break;

            case StartupManagerCommunication.RemoveAutostartEntry:
                AutostartManager.RemoveAutostartEntry((AutostartLocation)parameter[2],
                                                      Encoding.UTF8.GetString(parameter, 3, parameter.Length - 3), parameter[1] == 1);
                data    = new byte[parameter.Length];
                data[0] = (byte)StartupManagerCommunication.ResponseAutostartEntryRemoved;
                Array.Copy(parameter, 1, data, 1, parameter.Length - 1);
                connectionInfo.CommandResponse(this, data);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }