Context Cleaner

Discussion in 'Nobody Cares' started by KoalaRimjob, Jul 9, 2012.

Encyclopedia Dramatica Forums
  1. KoalaRimjob

    KoalaRimjob
    Expand Collapse
    EDF Elite

    Joined:
    Jul 15, 2011
    Messages:
    2,057
    Occupation:
    Server Administration
    [​IMG]

    I haven't been active lately because were getting ready for server 2012 at work and im deploying it at home. While i was on my domain controller looking for a setting to turn the little fuckers off (there is none) i made this program in c# to delete them all when you login

    Usage

    Find the context menu registry entry in the registry and use the "copy path" context menu entry in regedit to get the full path to the key eg HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\Adobe.Acrobat.ContextMenu

    add this to the array of keys to delete using ContextItems.Add(@"YOUR REG KEY HERE");

    repeat for all the annoying Shell Extensions you can find then compile the program in visual c#

    finally if you are in an active directory environment add it to a group policy object as a logon script otherewise you can use the startup folder with the "run as administrator" setting

    And Shell Extensions will never be seen again

    For security it wont delete keys with any more than 1 subkey named "command"


    Code:
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using Microsoft.Win32;
    
    namespace ContextCleaner
    {
        internal static class Program
        {
            private static RegistryKey ContextItem;
    
            [STAThread]
            private static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
    
                var ContextItems = new List<string>();
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\{a45cfb7d-6e23-40b5-94fa-290314f01dc5}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\AcShellExtension.AcContextMenuHandler");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\Adobe.Acrobat.ContextMenu");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\Autodesk.DWF.ContextMenu");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\DiffDogFileHandlerMenu");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\WS_FTP");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\XXX Groove GFS Context Menu Handler XXX");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers\{474C98EE-CF3D-41f5-80E3-4AAB0AB04301}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers\{596AB062-B4D2-4215-9F74-E9109B0A8153}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers\XXX Groove GFS Context Menu Handler XXX");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Application.Reference\shellex\ContextMenuHandlers\{90AA3A4E-1CBA-4233-B8BB-535773D48449}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Application.Reference\shellex\ContextMenuHandlers\{a2a9545d-a0c2-42b4-9708-a0b2badd77c8}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\CompressedFolder\ShellEx\ContextMenuHandlers\{b8cdcb65-b1bf-4b42-9428-1dfdb7ee92af}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\background\shellex\ContextMenuHandlers\DiffDogFileHandlerMenu");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\background\shellex\ContextMenuHandlers\XXX Groove GFS Context Menu Handler XXX");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers\DiffDogFileHandlerMenu");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers\XXX Groove GFS Context Menu Handler XXX");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Drive\shellex\ContextMenuHandlers\DiffDogFileHandlerMenu");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Drive\shellex\ContextMenuHandlers\{4648F940-EFE3-4BAB-9211-3BE45CD5029D}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Drive\shellex\ContextMenuHandlers\{59099400-57FF-11CE-BD94-0020AF85B590}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Drive\shellex\ContextMenuHandlers\{596AB062-B4D2-4215-9F74-E9109B0A8153}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Drive\shellex\ContextMenuHandlers\{fbeb8a05-beee-4442-804e-409d6c4515e9}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\Adobe.Acrobat.ContextMenu");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\WS_FTP");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\XXX Groove GFS Context Menu Handler XXX");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\LibraryFolder\background\shellex\ContextMenuHandlers\{FD62EEF6-2AB3-411D-986E-916210538B31}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\dllfile\shell\Browse in .NET Reactor");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\exefile\shell\Browse in .NET Reactor");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\shell\Bridge");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers\{a45cfb7d-6e23-40b5-94fa-290314f01dc5}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\InternetShortcut\ShellEx\ContextMenuHandlers\{a45cfb7d-6e23-40b5-94fa-290314f01dc5}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\lnkfile\shellex\ContextMenuHandlers\{a45cfb7d-6e23-40b5-94fa-290314f01dc5}");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\ESET Smart Security - Context Menu Shell Extension");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Drive\shellex\ContextMenuHandlers\ESET Smart Security - Context Menu Shell Extension");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Drives\Shellex\ContextMenuHandlers\ESET Smart Security - Context Menu Shell Extension");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\ESET Smart Security - Context Menu Shell Extension");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shellex\ContextMenuHandlers\ESET Smart Security - Context Menu Shell Extension");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Drive\shellex\ContextMenuHandlers\ESET Smart Security - Context Menu Shell Extension");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Drives\Shellex\ContextMenuHandlers\ESET Smart Security - Context Menu Shell Extension");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shellex\ContextMenuHandlers\ESET Smart Security - Context Menu Shell Extension");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\WinRAR");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers\WinRAR");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\shellex\DragDropHandlers\WinRAR");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\shellex\DragDropHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\shellex\DragDropHandlers\WS_FTP");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Drive\shellex\DragDropHandlers\WinRAR");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Drive\shellex\DragDropHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\WinRAR");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Folder\shellex\DragDropHandlers\WinRAR");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Folder\shellex\DragDropHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shellex\ContextMenuHandlers\WinRAR");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shellex\ContextMenuHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shellex\ContextMenuHandlers\WinRAR");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shellex\ContextMenuHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shellex\DragDropHandlers\WinRAR");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shellex\DragDropHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shellex\DragDropHandlers\WS_FTP");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Drive\shellex\DragDropHandlers\WinRAR");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Drive\shellex\DragDropHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shellex\ContextMenuHandlers\WinRAR");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shellex\ContextMenuHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shellex\DragDropHandlers\WinRAR");
                ContextItems.Add(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shellex\DragDropHandlers\WinRAR32");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\UltraEdit");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Directory\shell\SpaceMonger");
                ContextItems.Add(@"HKEY_CLASSES_ROOT\Drive\shell\SpaceMonger");
    
                //ContextItems.Add(@"");
                RegistryKey RegistrySection = null;
                foreach (string Item in ContextItems)
                {
                    string RegistryPath;
                    string RegistryPathWithoutGUID = null;
                    string ItemGuid = null;
                    RegistryKey Subkeys;
    
                    int index = Item.IndexOf(@"\");
                    string RegistryItem = null;
                    if (index > 0)
                    {
                        RegistryItem = Item.Substring(0, index);
                        RegistryPath = Item.Substring(index + 1, Item.Length - index - 1);
                        RegistryPathWithoutGUID = RegistryPath.Substring(0, RegistryPath.LastIndexOf(@"\"));
                        ItemGuid = RegistryPath.Substring(RegistryPath.LastIndexOf(@"\") + 1, RegistryPath.Length - RegistryPath.LastIndexOf(@"\") - 1);
                    }
    
    
                    switch (RegistryItem)
                    {
                        case "HKEY_CLASSES_ROOT":
                            RegistrySection = Registry.ClassesRoot;
                            break;
                        case "HKEY_CURRENT_USER":
                            RegistrySection = Registry.CurrentUser;
                            break;
                        case "HKEY_LOCAL_MACHINE":
                            RegistrySection = Registry.LocalMachine;
                            break;
                        case "HKEY_USERS":
                            RegistrySection = Registry.Users;
                            break;
                        case "HKEY_CURRENT_CONFIG":
                            RegistrySection = Registry.CurrentConfig;
                            break;
                    }
    
                    try
                    {
                        ContextItem = RegistrySection;
                    }
                    catch (Exception)
                    {
                    }
                    try
                    {
                        if (RegistryPathWithoutGUID != null) ContextItem = ContextItem.OpenSubKey(RegistryPathWithoutGUID, true);
                    }
                    catch
                    {
                        continue;
                    }
                    var subkeys = new string[] {};
                    try
                    {
                        RegistryKey Tempkey = RegistrySection;
                        if (Tempkey != null)
                        {
                            if (RegistryPathWithoutGUID != null)
                            {
                                RegistryKey OpenSubKey = Tempkey.OpenSubKey(RegistryPathWithoutGUID);
                                if (OpenSubKey != null) if (ItemGuid != null) Tempkey = OpenSubKey.OpenSubKey(ItemGuid);
                            }
                            subkeys = Tempkey.GetSubKeyNames();
                        }
                        if (subkeys.Length < 2)
                        {
                            if (subkeys.Length == 0)
                            {
                                if (ContextItem != null) if (ItemGuid != null) ContextItem.DeleteSubKeyTree(ItemGuid);
                            }
                            else if (subkeys.Length != 0)
                            {
                                if (subkeys[0] == "command")
                                {
                                    if (ContextItem != null) if (ItemGuid != null) ContextItem.DeleteSubKeyTree(ItemGuid);
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
    }