Add your own commands to the Explorer context menu

    Once I already told on Habr how it is possible to add own command to the context menu of the Internet Explorer browser ( Convenient addition to IE when writing reviews / Internet Explorer / Habrahabr ). Now I will tell you how to add my command to the Explorer context menu. Go.



    Information about the context menu of Explorer and the Desktop is stored in the registry key HKEY_CLASSES_ROOT \ Directory \ Background \ Shell . It is from here that the system learns which commands to display in the context menu and which programs to run when the user clicks on the selected menu command. Thus, armed with this knowledge, we will be able to create the teams we need ourselves.

    So, to add a new command to the context menu, just create in the sectionHKCR \ Directory \ Background \ Shell is a new subkey. Suppose we want a command to launch a standard Notepad in the menu. We create a subsection notepad and immediately we can check and make sure that the command of the same name appears in the context menu of the Desktop. We did not even have to restart the computer. Naturally, such a team does not suit us very much, and we want to set our own text, for example, Notepad . To do this, edit the default parameter of the created subsection and write a new value for it, which we want to see, for example, write the word Notepad . We check again and make sure that our team has appeared in the context menu.



    Now we’ll configure other parameters so that the created team responds to mouse clicks. A subsection can contain other nested subsections and various string type parameters. First, consider the options. We already know that the default parameter defines the name of the command. You can also use the following parameters (I give only part of the possible parameters):
    • MUIVerb - the value of this parameter replaces the default value of the parameter, i.e. we can set a name for the command in the menu in this parameter.
    • Extended - if this parameter is present without a value, it tells the system that the command should be displayed only when the Shift key is pressed. You can look at the subkey HKEY_CLASSES_ROOT \ Directory \ Background \ shell \ cmd , which contains such a parameter. Therefore, if you hold down the Shift key, the Open command window command will appear in the context menu .


    Now let's move on to the subsections. First of all, you need to create a command subsection . The default parameter of this subsection should contain a command that will be executed when the corresponding context menu item is selected. In our case, you need to register the notepad.exe command.



    As you can see, there are several simple operations in the registry section and we get a new command for the desktop and Explorer context menu. And knowing the algorithm for creating a new team, you can study and edit parameters from other programs that have registered their sections in your system.

    Turn on / off thumbnails



    Consider a practical example of creating your own command in the Explorer menu. If you prefer to view files in the Icon mode, you have noticed that, for example, image icons are displayed as thumbnails. In the folder settings, you can change this behavior and disable the display of thumbnails. But turning these settings on or off is very tedious. Judge for yourself - first you need to press the Alt key so that the Explorer menu bar appears, then select the Tools | Folder Options ... . After that, you need to switch to the View tab and check or uncheck the Always show icons, not thumbnails box . We simplify the task with the help of the registry and a small VBS script that cyclically changes the values ​​of the IconsOnly parameter in the sectionHKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced . Create a new ToggleThumb section in the HKEY_CURRENT_USER \ Software \ Classes \ Directory \ Background \ Shell section and set the default value to the On / Off thumbnails string value . Thus, we created a new command for the context menu of the folder in Explorer. Please note that we are now using the HKEY_CURRENT_USER section so that the example applies only to one user. Now create the command subsection and set the line wscript.exe "% WinDir% \ togglethumbs.vbs" in the default parameter . Next, you need to create a script that will switch the thumbnail display mode.

    Set WshShell = CreateObject ("WScript.Shell")
    strValue = "HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced \ IconsOnly"
    strIconsOnly = WshShell.RegRead (strValue)
    If strIconsOnly = 0 Then
    WshShell.RegWrite strValue, 1, "REG_DWORD"
    Else
    WshShell.RegWrite strValue, 0, "REG_DWORD"
    End if
    WshShell.SendKeys "{F5}"
    


    Save the created script as togglethumbs.vbs and copy it to the Windows folder.
    Now you can open the Explorer and check the work of the new team. For convenience, I first selected the Large Icons mode, which appears as thumbnails.

    Display files as thumbnails

    Next, I selected the Enable / Disable thumbnails item in the context menu and got the following result - instead of the thumbnails, I saw Adobe Photoshop program icons, a trial version of which I put on my computer a few days ago.

    Display files as icons

    I got the idea for this example from http://www.winhelponline.com/blog/toggle-thumbnail-previews-right-click-menu-windows-vista-windows-7/and modified it a bit. The author of the original example suggests using the ready-made REG-files for creating (togglethumbs.reg) and deleting (undo.reg) sections for a new team, as well as a ready-made script (togglethumbs.vbs) for greater convenience. On my own, I’ll add that copying the script file to the Windows folder used by the author of the idea is not the best option, since this folder is protected and there is no need to litter it with your own files. Therefore, if you use the example on your computer, then redo it so that the script file is in a more accessible place for the user.

    Removing the contents of a folder without deleting the folder itself



    In almost the same way, a custom command is added to the context menu of a folder. Recently, I found one example of using the context menu of a folder in Explorer - Add Empty Folder Contents to Windows 7 Right Click Context Menu. | The Windows Club .

    The author of the example tells how to add a command to the folder context menu to delete the contents of a folder without deleting the folder itself. Those. You don’t have to open the folder, select all the files and press the Delete key, just select the Delete folder contents command . I modified the example a bit so that it looks more organically on the Russian version of Windows.

    To do this, add the DeleteFolderContent subkey to the HKEY_CLASSES_ROOT \ Directory \ shell section and create a string parameter in itMUIVerb with the line Delete folder contents . Next, in the DeleteFolderContent section , create the command subsection and set the line in its default parameter:

    cmd / c "cd / d% 1 && del / s / f / q *. *"
    


    Everything is ready and you can use the example.

    Conclusion



    I want to warn you that I talked about the basic techniques for creating commands in the Explorer context menu. The registry is a rather complicated thing and there are other ways to work with the context menu.

    As you can see, you can configure the Explorer context menu yourself. It all depends on your imagination. If you need additional information about the registry settings, you can download the electronic registry Windows Registry on my site user.alexanderklimov.ru. In addition, a preliminary agreement was reached with one publisher on the release of a book on the Windows 7 registry. As they say, stay tuned. By the way, while working on the book, I found that so many parameters are outdated and it is time to remove them from the directory. But, since the number of Windows XP users is still large, I decided to create a certain settling page , where I will reset the old parameters.

    PS Strictly speaking, the context menu settings in Explorer are available in other versions of Windows, including Windows XP. But, I have long switched to Windows 7, so I publish this post in this blog.


    Also popular now: