예제 #1
0
        public override void Setup(ICollection <ApplicationUninstallerEntry> allUninstallers)
        {
            base.Setup(allUninstallers);

            _comEntries = new List <ComEntry>();

            _extensionKeyNames = new Dictionary <string, string[]>();

            foreach (var classesKeyPath in _classesKeys)
            {
                using (var classesKey = RegistryTools.OpenRegistryKey(classesKeyPath, false, true))
                {
                    if (classesKey == null)
                    {
                        continue;
                    }

                    _extensionKeyNames.Add(classesKeyPath, classesKey.GetSubKeyNames().Where(x => x[0] == '.').ToArray());

                    try
                    {
                        GetClsidEntries(_comEntries, classesKey);
                        GetTypeLibEntries(_comEntries, classesKey);
                    }
                    catch (SystemException ex)
                    {
                        Console.WriteLine(@"Unexpected error while scanning COM entries, the registry might be corrupted. COM junk detection will not work.");
                        Console.WriteLine(ex);
                    }
                }
            }

            // Gather com interface info
            // https://docs.microsoft.com/en-us/windows/desktop/com/interface-key
            foreach (var classesKeyPath in _classesKeys)
            {
                using (var interfacesKey = RegistryTools.OpenRegistryKey(Path.Combine(classesKeyPath, "Interface"), false, true))
                {
                    if (interfacesKey == null)
                    {
                        continue;
                    }

                    foreach (var singleInterfaceKey in interfacesKey.GetSubKeyNames())
                    {
                        using (var proxyKey = interfacesKey.OpenSubKey(Path.Combine(singleInterfaceKey, "ProxyStubClsid32")))
                        {
                            var proxyGuid = proxyKey?.GetValue(null, null) as string;
                            if (proxyGuid == null)
                            {
                                continue;
                            }

                            var matchClass = _comEntries.FirstOrDefault(x => string.Equals(x.Guid, proxyGuid, StringComparison.OrdinalIgnoreCase));
                            matchClass?.InterfaceNames.Add(Path.Combine(interfacesKey.Name, singleInterfaceKey));
                        }
                    }
                }
            }
        }
예제 #2
0
 public override void Delete()
 {
     using (var key = RegistryTools.OpenRegistryKey(ParentPath, true))
     {
         key?.DeleteSubKeyTree(Name);
     }
 }
예제 #3
0
        public IEnumerable <IJunkResult> FindJunk(ApplicationUninstallerEntry target)
        {
            var returnList = new List <IJunkResult>();

            if (string.IsNullOrEmpty(target.InstallLocation))
            {
                return(returnList);
            }

            string pathRoot;

            try
            {
                pathRoot = Path.GetPathRoot(target.InstallLocation);
            }
            catch (SystemException ex)
            {
                Console.WriteLine(ex);
                return(returnList);
            }

            var unrootedLocation = pathRoot.Length >= 1
                ? target.InstallLocation.Replace(pathRoot, string.Empty)
                : target.InstallLocation;

            if (string.IsNullOrEmpty(unrootedLocation.Trim()))
            {
                return(returnList);
            }

            using (var key = RegistryTools.OpenRegistryKey(Path.Combine(SoftwareRegKeyScanner.KeyCu, AudioPolicyConfigSubkey)))
            {
                if (key == null)
                {
                    return(returnList);
                }

                foreach (var subKeyName in key.GetSubKeyNames())
                {
                    using (var subKey = key.OpenSubKey(subKeyName))
                    {
                        if (subKey == null)
                        {
                            continue;
                        }

                        var defVal = subKey.GetValue(null) as string;
                        if (defVal != null &&
                            defVal.Contains(unrootedLocation, StringComparison.InvariantCultureIgnoreCase))
                        {
                            var junk = new RegistryKeyJunk(subKey.Name, target, this);
                            junk.Confidence.Add(ConfidenceRecords.ExplicitConnection);
                            returnList.Add(junk);
                        }
                    }
                }
            }

            return(returnList);
        }
예제 #4
0
        public SettingsWindow()
        {
            Opacity = 0;

            InitializeComponent();

            Icon = Resources.editoricon;

            var settings = Settings.Default.Binder;

            settings.BindControl(checkBoxRestoreSessionSettings, s => s.RestoreSessionSettingsOnExit, this);
            settings.SendUpdates(this);

            try
            {
                using (var key = RegistryTools.OpenRegistryKey(RunKeyPath))
                {
                    checkBoxBoot.Checked = key?.GetValue(RunKeyValueName) != null;
                }
            }
            catch (Exception ex)
            {
                ShowBootException(ex);
                checkBoxBoot.Enabled = false;
            }
            checkBoxBoot.CheckedChanged += checkBoxBoot_CheckedChanged;
        }
        public bool StillExists(StartupEntry startupEntry)
        {
            if (startupEntry.IsRegKey)
            {
                using (var key = RegistryTools.OpenRegistryKey(startupEntry.ParentLongName))
                    return(!string.IsNullOrEmpty(key.GetStringSafe(startupEntry.EntryLongName)));
            }

            return(File.Exists(startupEntry.FullLongName));
        }
 private static Microsoft.Win32.RegistryKey GetFirewallRulesKey()
 {
     try
     {
         return(RegistryTools.OpenRegistryKey(FirewallRulesKey));
     }
     catch (SystemException ex)
     {
         Console.WriteLine(ex);
         return(null);
     }
 }
예제 #7
0
        /// <summary>
        ///     Create a registry value for the specified entry. Works for drive links as well.
        /// </summary>
        /// <param name="startupEntry"></param>
        internal static void CreateRegValue(StartupEntry startupEntry)
        {
            if (string.IsNullOrEmpty(startupEntry.Command))
            {
                return;
            }

            using (var runKey = RegistryTools.OpenRegistryKey(startupEntry.ParentLongName, true))
            {
                runKey.SetValue(startupEntry.EntryLongName, startupEntry.Command, RegistryValueKind.String);
            }
        }
예제 #8
0
        private IEnumerable <JunkNode> ScanRelatedKeys(IEnumerable <JunkNode> itemsToCompare)
        {
            var input  = itemsToCompare.ToList();
            var output = new List <JunkNode>();

            foreach (var registryJunkNode in input)
            {
                var nodeName = registryJunkNode.FullName;

                // Check Wow first because non-wow path will match wow path
                var softwareKey = new[] { KeyLmWow, KeyCuWow, KeyLm, KeyCu }.First(
                    key => nodeName.StartsWith(key, StringComparison.InvariantCultureIgnoreCase));

                nodeName = nodeName.Substring(softwareKey.Length + 1);

                foreach (var keyToTest in SoftwareRegKeys.Except(new[] { softwareKey }))
                {
                    var nodePath = Path.Combine(keyToTest, nodeName);
                    // Check if the same node exists in other root keys
                    var node = input.FirstOrDefault(x => PathTools.PathsEqual(x.FullName, nodePath));

                    if (node != null)
                    {
                        // Add any non-duplicate confidence to the existing node
                        node.Confidence.AddRange(registryJunkNode.Confidence.ConfidenceParts
                                                 .Where(x => !node.Confidence.ConfidenceParts.Any(x.Equals)));
                    }
                    else
                    {
                        try
                        {
                            // Check if the key acually exists
                            using (var nodeKey = RegistryTools.OpenRegistryKey(nodePath, false))
                            {
                                if (nodeKey != null)
                                {
                                    var newNode = new RegistryKeyJunkNode(Path.GetDirectoryName(nodePath),
                                                                          Path.GetFileName(nodePath), Uninstaller.DisplayName);
                                    newNode.Confidence.AddRange(registryJunkNode.Confidence.ConfidenceParts);
                                    output.Add(newNode);
                                }
                            }
                        }
                        catch
                        {
                            // Ignore keys that don't exist
                        }
                    }
                }
            }

            return(output);
        }
예제 #9
0
        private static void GetTypeLibEntries(ICollection <ComEntry> results, RegistryKey classes)
        {
            using (var typeLibKey = RegistryTools.OpenRegistryKey(Path.Combine(classes.Name, "TypeLib"), false, true))
            {
                if (typeLibKey == null)
                {
                    return;
                }

                foreach (var typeLibKeyGuid in typeLibKey.GetSubKeyNames())
                {
                    if (IsSystemGuid(typeLibKeyGuid))
                    {
                        continue;
                    }

                    using (var guidKey = typeLibKey.OpenSubKey(typeLibKeyGuid))
                    {
                        var versionKeyName = guidKey?.GetSubKeyNames().FirstOrDefault();
                        if (versionKeyName == null)
                        {
                            continue;
                        }

                        var result = results.FirstOrDefault(x => string.Equals(x.Guid, typeLibKeyGuid, StringComparison.OrdinalIgnoreCase)) ?? new ComEntry(typeLibKeyGuid);

                        foreach (var fileKeyPath in new[] { Path.Combine(versionKeyName, "0\\win32"), Path.Combine(versionKeyName, "0\\win64") })
                        {
                            using (var fileKey = guidKey.OpenSubKey(fileKeyPath))
                            {
                                var path = fileKey?.GetValue(null, null) as string;
                                if (string.IsNullOrEmpty(path))
                                {
                                    continue;
                                }

                                path = PathTools.NormalizePath(path);
                                if (UninstallToolsGlobalConfig.IsSystemDirectory(path))
                                {
                                    continue;
                                }

                                result.FullFilename = PathTools.NormalizePath(Environment.ExpandEnvironmentVariables(path));
                                results.Add(result);
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #10
0
        private IEnumerable <JunkNode> ScanAudioPolicyConfig()
        {
            var returnList = new List <JunkNode>();

            if (string.IsNullOrEmpty(Uninstaller.InstallLocation))
            {
                return(returnList);
            }

            var pathRoot         = Path.GetPathRoot(Uninstaller.InstallLocation);
            var unrootedLocation = pathRoot.Length >= 1
                ? Uninstaller.InstallLocation.Replace(pathRoot, string.Empty)
                : Uninstaller.InstallLocation;

            if (string.IsNullOrEmpty(unrootedLocation.Trim()))
            {
                return(returnList);
            }

            using (var key = RegistryTools.OpenRegistryKey(Path.Combine(KeyCu,
                                                                        @"Microsoft\Internet Explorer\LowRegistry\Audio\PolicyConfig\PropertyStore")))
            {
                if (key == null)
                {
                    return(returnList);
                }

                foreach (var subKeyName in key.GetSubKeyNames())
                {
                    using (var subKey = key.OpenSubKey(subKeyName))
                    {
                        if (subKey == null)
                        {
                            continue;
                        }

                        var defVal = subKey.GetValue(null) as string;
                        if (defVal != null &&
                            defVal.Contains(unrootedLocation, StringComparison.InvariantCultureIgnoreCase))
                        {
                            var junk = new RegistryKeyJunkNode(key.Name, subKeyName, Uninstaller.DisplayName);
                            junk.Confidence.Add(ConfidencePart.ExplicitConnection);
                            returnList.Add(junk);
                        }
                    }
                }
            }

            return(returnList);
        }
 public override void Delete()
 {
     try
     {
         using (var key = RegistryTools.OpenRegistryKey(ParentPath, true))
         {
             key.DeleteSubKeyTree(Name);
         }
     }
     catch (Exception ex)
     {
         // Failed to remove the key
         Debug.WriteLine("RegistryJunkNode\\Delete -> " + ex.Message);
     }
 }
        public override void CreateBackup(string backupPath)
        {
            var path = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\" + ProgramName;

            using (var key = RegistryTools.OpenRegistryKey(path))
            {
                if (key == null)
                {
                    throw new IOException();
                }
            }

            var filename = PathTools.SanitizeFileName(FullLongName) + ".reg";

            RegistryTools.ExportRegistry(Path.Combine(backupPath, filename), new[] { path });
        }
예제 #13
0
        private IEnumerable <JunkNode> ScanForJunk()
        {
            var output = new List <JunkNode>();

            foreach (var softwareKeyName in SoftwareRegKeys)
            {
                using (var softwareKey = RegistryTools.OpenRegistryKey(softwareKeyName))
                {
                    if (softwareKey != null)
                    {
                        output.AddRange(FindJunkRecursively(softwareKey));
                    }
                }
            }

            return(output.Concat(ScanRelatedKeys(output)));
        }
예제 #14
0
 public void Setup(ICollection <ApplicationUninstallerEntry> allUninstallers)
 {
     try
     {
         using (var key = RegistryTools.OpenRegistryKey(RegKey))
         {
             if (key != null)
             {
                 // Reg key names are case insensitive so using tolower key is fine
                 _lookup = key.GetSubKeyNames().ToDictionary(x => x.ToLower(), x => x);
             }
         }
     }
     catch (SystemException ex)
     {
         Console.WriteLine(ex);
     }
 }
        public override IEnumerable <IJunkResult> FindJunk(ApplicationUninstallerEntry target)
        {
            _uninstaller = target;
            var output = new List <RegistryKeyJunk>();

            foreach (var softwareKeyName in SoftwareRegKeys)
            {
                using (var softwareKey = RegistryTools.OpenRegistryKey(softwareKeyName))
                {
                    if (softwareKey != null)
                    {
                        output.AddRange(FindJunkRecursively(softwareKey));
                    }
                }
            }

            return(output.Concat(ScanRelatedKeys(output)).Cast <IJunkResult>());
        }
예제 #16
0
        /// <summary>
        ///     Remove registry key of a disabled startup entry. Link file is not touched if it exists.
        /// </summary>
        private static void RemoveDisabledRegEntry(StartupEntry startupEntry)
        {
            using (var disabledStartupEntryStore = RegistryTools.OpenRegistryKey(
                       startupEntry.IsRegKey ? RegistryDisabledKey.Path : DriveDisabledKey.Path, true))
            {
                var disabledSubKeyName = startupEntry.IsRegKey
                    ? startupEntry.EntryLongName
                    : startupEntry.FullLongName.Replace('\\', '^');
                var disabledSubkeyKey =
                    disabledStartupEntryStore.GetSubKeyNames()
                    .FirstOrDefault(x => disabledSubKeyName.Equals(x, StringComparison.InvariantCultureIgnoreCase));

                if (!string.IsNullOrEmpty(disabledSubkeyKey))
                {
                    disabledStartupEntryStore.DeleteSubKey(disabledSubkeyKey);
                }
            }
        }
예제 #17
0
 public bool StillExists(StartupEntry startupEntry)
 {
     try
     {
         using (var key = RegistryTools.OpenRegistryKey(
                    startupEntry.IsRegKey ? RegistryDisabledKey.Path : DriveDisabledKey.Path))
         {
             var disabledSubKeyName = startupEntry.IsRegKey
                 ? startupEntry.EntryLongName
                 : startupEntry.FullLongName.Replace('\\', '^');
             return(key.GetSubKeyNames()
                    .Any(x => disabledSubKeyName.Equals(x, StringComparison.InvariantCultureIgnoreCase)));
         }
     }
     catch
     {
         return(false);
     }
 }
        private void FindJunkRecursively(ICollection <RegistryJunkNode> returnList, string softwareKey, int level)
        {
            try
            {
                string[] names;
                using (var key = RegistryTools.OpenRegistryKey(softwareKey))
                {
                    names = key.GetSubKeyNames();
                }

                foreach (var name in names)
                {
                    if (KeyBlacklist.Any(y => y.Equals(name)))
                    {
                        continue;
                    }

                    var generatedConfidence = GenerateConfidence(name, softwareKey, level, false);
                    var confidenceParts     = generatedConfidence as IList <ConfidencePart> ?? generatedConfidence.ToList();

                    if (confidenceParts.Any())
                    {
                        var newNode = new RegistryJunkNode(softwareKey, name, Uninstaller.DisplayName);
                        newNode.Confidence.AddRange(confidenceParts);
                        returnList.Add(newNode);
                    }
                    else if (level <= 1)
                    {
                        FindJunkRecursively(returnList, Path.Combine(softwareKey, name), level + 1);
                    }
                }
            }
            // Reg key invalid
            catch (ArgumentException)
            {
            }
            catch (SecurityException)
            {
            }
            catch (ObjectDisposedException)
            {
            }
        }
예제 #19
0
        public static IEnumerable <BrowserHelperEntry> GetBrowserHelpers()
        {
            using (var clsidKey = RegistryTools.OpenRegistryKey(ClsidPath))
            {
                foreach (var registryStartupPoint in RegistryStartupPoints)
                {
                    RegistryKey mainKey;

                    try
                    {
                        mainKey = RegistryTools.CreateSubKeyRecursively(registryStartupPoint);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        Console.WriteLine(e);
                        continue;
                    }

                    using (mainKey)
                    {
                        foreach (var browserHelperEntry in
                                 GatherBrowserHelpersFromKey(mainKey, clsidKey, registryStartupPoint, false))
                        {
                            yield return(browserHelperEntry);
                        }

                        using (var disabledKey = mainKey.OpenSubKey(AutorunsDisabledKeyName))
                        {
                            if (disabledKey == null)
                            {
                                continue;
                            }

                            foreach (var browserHelperEntry in
                                     GatherBrowserHelpersFromKey(disabledKey, clsidKey, registryStartupPoint, true))
                            {
                                yield return(browserHelperEntry);
                            }
                        }
                    }
                }
            }
        }
        /// <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);
        }
        public override void Backup(string backupDirectory)
        {
            using (var key = RegistryTools.OpenRegistryKey(ParentPath))
            {
                var target = key.GetValue(Name);

                var targetValue = target as string;
                if (targetValue != null)
                {
                    var dir      = CreateBackupDirectory(backupDirectory);
                    var fileName = PathTools.SanitizeFileName(FullName.TrimStart('\\').Replace('.', '_')) + ".reg";
                    RegistryTools.ExportRegistryStringValues(Path.Combine(dir, fileName), ParentPath,
                                                             new KeyValuePair <string, string>(Name, targetValue));
                }
                else
                {
                    Debug.Fail("Unsupported type " + target.GetType().FullName);
                }
            }
        }
        public IEnumerable <IJunkResult> FindJunk(ApplicationUninstallerEntry target)
        {
            if (string.IsNullOrEmpty(target.InstallLocation))
            {
                yield break;
            }

            foreach (var userAssistGuid in UserAssistGuids)
            {
                using (var key = RegistryTools.OpenRegistryKey(
                           $@"{SoftwareRegKeyScanner.KeyCu}\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{userAssistGuid}\Count"))
                {
                    if (key == null)
                    {
                        continue;
                    }

                    foreach (var valueName in key.GetValueNames())
                    {
                        // Convert the value name to a usable form
                        var  convertedName = Rot13(valueName);
                        var  guidEnd       = convertedName.IndexOf('}') + 1;
                        Guid g;
                        if (guidEnd > 0 && GuidTools.GuidTryParse(convertedName.Substring(0, guidEnd), out g))
                        {
                            convertedName = NativeMethods.GetKnownFolderPath(g) + convertedName.Substring(guidEnd);
                        }

                        // Check for matches
                        if (convertedName.StartsWith(target.InstallLocation,
                                                     StringComparison.InvariantCultureIgnoreCase))
                        {
                            var junk = new RegistryValueJunk(key.Name, valueName, target, this);
                            junk.DisplayValueName = convertedName;
                            junk.Confidence.Add(ConfidenceRecords.ExplicitConnection);
                            yield return(junk);
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     Check if the startup entry still exists in registry or on disk.
        ///     If the entry is disabled, but it exists in the backup store, this method will return true.
        /// </summary>
        public override bool StillExists()
        {
            try
            {
                if (Disabled)
                {
                    return(StartupEntryManager.DisableFunctions.StillExists(this));
                }

                if (!IsRegKey)
                {
                    return(File.Exists(FullLongName));
                }

                using (var key = RegistryTools.OpenRegistryKey(ParentLongName))
                    return(!string.IsNullOrEmpty(key.GetValue(EntryLongName) as string));
            }
            catch
            {
                return(false);
            }
        }
예제 #24
0
        public override string CategoryName => Localisation.Junk_Clsid_GroupName; // "COM Objects";

        public override IEnumerable <IJunkResult> FindJunk(ApplicationUninstallerEntry target)
        {
            if (!_classesKeys.Any())
            {
                yield break;
            }

            if (string.IsNullOrEmpty(target.InstallLocation) ||
                UninstallToolsGlobalConfig.IsSystemDirectory(target.InstallLocation))
            {
                yield break;
            }

            foreach (var comEntry in _comEntries.Where(x => SubPathIsInsideBasePath(target.InstallLocation, x.FullFilename)))
            {
                foreach (var interfacePath in comEntry.InterfaceNames)
                {
                    using (var interfaceKey = RegistryTools.OpenRegistryKey(interfacePath, false, true))
                    {
                        if (interfaceKey != null)
                        {
                            yield return(JunkFromKey(target, interfaceKey));
                        }
                    }
                }

                foreach (var classesKeyPath in _classesKeys)
                {
                    using (var classesKey = RegistryTools.OpenRegistryKey(classesKeyPath, false, true))
                    {
                        if (classesKey == null)
                        {
                            continue;
                        }

                        foreach (var targetSubKeyPath in new[]
                        {
                            Path.Combine("CLSID", comEntry.Guid),
                            Path.Combine("TypeLib", comEntry.Guid),
                            comEntry.ProgId,
                            comEntry.VersionIndependentProgId
                        })
                        {
                            if (targetSubKeyPath != null)
                            {
                                var result = TryGetFromPath(target, classesKey, targetSubKeyPath);
                                if (result != null)
                                {
                                    yield return(result);
                                }
                            }
                        }

                        foreach (var extensionKeyName in GetExtensionNames(classesKeyPath))
                        {
                            using (var extensionKey = classesKey.OpenSubKey(extensionKeyName))
                            {
                                if (extensionKey == null)
                                {
                                    continue;
                                }

                                // Contains subkeys with default values containing class guids of the extensions
                                using (var shellExKey = extensionKey.OpenSubKey("ShellEx"))
                                {
                                    if (shellExKey != null)
                                    {
                                        foreach (var shellSubKeyName in shellExKey.GetSubKeyNames())
                                        {
                                            using (var shellSubKey = shellExKey.OpenSubKey(shellSubKeyName))
                                            {
                                                if (string.Equals(shellSubKey?.GetValue(null, null) as string, comEntry.Guid, StringComparison.OrdinalIgnoreCase))
                                                {
                                                    yield return(JunkFromKey(target, shellSubKey));
                                                }
                                            }
                                        }
                                    }
                                }

                                // Contains default value pointing to a class guid
                                using (var persistentHandlerKey = extensionKey.OpenSubKey("PersistentHandler"))
                                {
                                    if (string.Equals(persistentHandlerKey?.GetValue(null, null) as string, comEntry.Guid, StringComparison.OrdinalIgnoreCase))
                                    {
                                        yield return(JunkFromKey(target, persistentHandlerKey));
                                    }
                                }

                                if (comEntry.ProgId != null || comEntry.VersionIndependentProgId != null)
                                {
                                    // Contains values with names corresponding to ProgIDs
                                    using (var openWithProgidsKey = extensionKey.OpenSubKey("OpenWithProgIDs"))
                                    {
                                        if (openWithProgidsKey != null)
                                        {
                                            foreach (var progIdName in openWithProgidsKey.GetValueNames())
                                            {
                                                if (string.Equals(progIdName, comEntry.ProgId, StringComparison.OrdinalIgnoreCase) ||
                                                    string.Equals(progIdName, comEntry.VersionIndependentProgId, StringComparison.OrdinalIgnoreCase))
                                                {
                                                    yield return(JunkFromValue(target, openWithProgidsKey.Name, progIdName));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #25
0
        private static ApplicationUninstallerEntry GetOneDrive()
        {
            var result = new ApplicationUninstallerEntry();

            // Check if installed
            try
            {
                using (var key = RegistryTools.OpenRegistryKey(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\OneDrive", false))
                {
                    result.RegistryPath    = key.Name;
                    result.RegistryKeyName = key.GetKeyName();

                    result.InstallLocation = key.GetValue("CurrentVersionPath") as string;
                    if (result.InstallLocation == null || !Directory.Exists(result.InstallLocation))
                    {
                        return(null);
                    }

                    result.DisplayIcon    = key.GetValue("OneDriveTrigger") as string;
                    result.DisplayVersion = ApplicationEntryTools.CleanupDisplayVersion(key.GetValue("Version") as string);
                }
            }
            catch
            {
                return(null);
            }

            // Check if the uninstaller is available
            var systemRoot    = WindowsTools.GetEnvironmentPath(CSIDL.CSIDL_WINDOWS);
            var uninstallPath = Path.Combine(systemRoot, @"System32\OneDriveSetup.exe");

            if (!File.Exists(uninstallPath))
            {
                uninstallPath = Path.Combine(systemRoot, @"SysWOW64\OneDriveSetup.exe");
                if (!File.Exists(uninstallPath))
                {
                    uninstallPath = null;
                }
            }

            if (uninstallPath != null)
            {
                result.IsValid              = true;
                result.UninstallString      = $"\"{uninstallPath}\" /uninstall";
                result.QuietUninstallString = result.UninstallString;
                if (!File.Exists(result.DisplayIcon))
                {
                    result.DisplayIcon = uninstallPath;
                }
            }

            result.AboutUrl       = @"https://onedrive.live.com/";
            result.RawDisplayName = "OneDrive";
            result.Publisher      = "Microsoft Corporation";
            result.EstimatedSize  = FileSize.FromKilobytes(1024 * 90);
            result.Is64Bit        = MachineType.X86;
            result.IsRegistered   = true;

            result.UninstallerKind = UninstallerType.Unknown;

            result.InstallDate = Directory.GetCreationTime(result.InstallLocation);

            if (!string.IsNullOrEmpty(result.DisplayIcon))
            {
                result.IconBitmap = UninstallToolsGlobalConfig.TryExtractAssociatedIcon(result.DisplayIcon);
            }

            return(result);
        }
예제 #26
0
        /// <summary>
        ///     Create a new record in the appropriate disabled entry store. If the entry already exists it is overwritten.
        /// </summary>
        /// <param name="startupEntry">Startup entry to create the record for</param>
        /// <param name="newEntryPath">Full path to the new backup file</param>
        private static void CreateDisabledEntry(StartupEntry startupEntry, string newEntryPath)
        {
            using (var disabledStartupEntryStore = RegistryTools.OpenRegistryKey(
                       startupEntry.IsRegKey ? RegistryDisabledKey.Path : DriveDisabledKey.Path, true))
            {
                var disabledSubKeyName = startupEntry.IsRegKey
                    ? startupEntry.EntryLongName
                    : startupEntry.FullLongName.Replace('\\', '^');
                var disabledSubkeyKey =
                    disabledStartupEntryStore.GetSubKeyNames()
                    .FirstOrDefault(x => disabledSubKeyName.Equals(x, StringComparison.InvariantCultureIgnoreCase));

                // Clean up old disabled entry if any
                if (!string.IsNullOrEmpty(disabledSubkeyKey))
                {
                    disabledStartupEntryStore.DeleteSubKey(disabledSubkeyKey);
                }

                using (
                    var storeSubkey = disabledStartupEntryStore.CreateSubKey(disabledSubKeyName,
                                                                             RegistryKeyPermissionCheck.ReadWriteSubTree))
                {
                    if (storeSubkey == null)
                    {
                        return;
                    }

                    if (startupEntry.IsRegKey)
                    {
                        storeSubkey.SetValue("key", RegistryTools.StripKeyRoot(startupEntry.ParentLongName),
                                             RegistryValueKind.String);
                        storeSubkey.SetValue("item", startupEntry.EntryLongName, RegistryValueKind.String);
                        storeSubkey.SetValue("hkey", RegistryTools.GetKeyRoot(startupEntry.ParentLongName, true),
                                             RegistryValueKind.String);
                        storeSubkey.SetValue("inimapping", 0, RegistryValueKind.String);
                    }
                    else
                    {
                        storeSubkey.SetValue("item",
                                             Path.GetFileNameWithoutExtension(startupEntry.EntryLongName) ?? string.Empty,
                                             RegistryValueKind.String);
                        storeSubkey.SetValue("path", startupEntry.FullLongName, RegistryValueKind.String);
                        storeSubkey.SetValue("location", startupEntry.ParentLongName, RegistryValueKind.String);
                        storeSubkey.SetValue("backup", newEntryPath, RegistryValueKind.String);
                        storeSubkey.SetValue("backupExtension", BackupExtension, RegistryValueKind.String);
                    }

                    // Command stays the same for both
                    storeSubkey.SetValue("command", startupEntry.Command, RegistryValueKind.String);

                    // Set the disable date
                    var now = DateTime.Now;
                    storeSubkey.SetValue("YEAR", now.Year, RegistryValueKind.DWord);
                    storeSubkey.SetValue("MONTH", now.Month, RegistryValueKind.DWord);
                    storeSubkey.SetValue("DAY", now.Day, RegistryValueKind.DWord);
                    storeSubkey.SetValue("HOUR", now.Hour, RegistryValueKind.DWord);
                    storeSubkey.SetValue("MINUTE", now.Minute, RegistryValueKind.DWord);
                    storeSubkey.SetValue("SECOND", now.Second, RegistryValueKind.DWord);
                }
            }
        }
 /// <summary>
 ///     Opens a new instance of registry key used by this uninstaller. Remember to close it!
 /// </summary>
 /// <exception cref="System.Security.SecurityException">
 ///     The user does not have the permissions required to access the registry key in the
 ///     specified mode.
 /// </exception>
 public RegistryKey OpenRegKey(bool writable)
 {
     return(RegistryTools.OpenRegistryKey(RegistryPath, writable));
 }
 /// <summary>
 ///     Opens a new read-only instance of registry key used by this uninstaller. Remember to close it!
 /// </summary>
 public RegistryKey OpenRegKey()
 {
     return(RegistryPath != null?RegistryTools.OpenRegistryKey(RegistryPath) : null);
 }
 public override bool StillExists()
 {
     using (var key = RegistryTools.OpenRegistryKey(GetRealParentPath()))
         return(key != null && key.GetSubKeyNames().Contains(EntryLongName));
 }
 public override void Delete()
 {
     using (var key = RegistryTools.OpenRegistryKey(GetRealParentPath(), true))
         key?.DeleteSubKey(EntryLongName);
 }