📜 ⬆️ ⬇️

Add our own commands to the Explorer context menu

Once I already told on Habré how you can add your own command to the context menu of the Internet Explorer browser (A convenient addition to IE when writing reviews / Internet Explorer / Habrahabr ). Now I will tell you how to add your command to the context menu of the Explorer. Go.



Information about the context menu of the Explorer and the Desktop is stored in the registry key HKEY_CLASSES_ROOT \ Directory \ Background \ Shell . It is from here that the system will know which commands need to be displayed in the context menu and which programs need to be launched when the user clicks on the selected menu command. Thus, armed with this knowledge, we will be able to create the teams we need.
')
So, to add a new command to the context menu, just create a new subkey in the HKCR \ Directory \ Background \ Shell section. Suppose we want a command to appear on the menu that starts a standard Notepad. We create a subsection of notepad and we can immediately check and make sure that the same-name command has appeared in the context menu of the Desktop. We didn't 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 that we want to see, for example, write the word Notepad . We check again and make sure that our command appeared in the context menu.



Now we configure other parameters so that the created command reacts to mouse clicks. A subsection may contain other nested subsections and various string type parameters. First, consider the parameters. We already know that the default parameter defines the name of the command. You can also use the following parameters (I present only a part of the possible parameters):


We now turn to subsections. First of all, you need to create a subsection of command . The default parameter of this subsection should contain a command that will be executed when selecting the corresponding item in the context menu. In our case, you need to register the notepad.exe command.



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

Turn on / off thumbnails



Consider a practical example of creating your own team in the Explorer menu. If you prefer to view files in Icon mode, you noticed that, for example, image icons are displayed as thumbnails. In the folder settings, you can change this behavior and disable thumbnail display. But to enable or disable these settings is very tedious. Judge for yourself - you first 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 display icons, not sketches box. Simplify the task using the registry and a small VBS script that cyclically changes the values ​​of the IconsOnly parameter in the HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced section. Create a new ToggleThumb section in the HKEY_CURRENT_USER \ Software \ Classes \ Directory \ Background \ Shell section and assign the string value Enable / Disable Thumbnails to the default parameter. Thus, we have created a new command for the context menu of the folder in Explorer. Notice that we now use the HKEY_CURRENT_USER section so that the example applies to only one user. Now we create a subsection of the command and set the default string wscript.exe "% WinDir% \ togglethumbs.vbs" in the parameter. Next you need to create a script that will switch the display mode thumbnails.

 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 Conductors and test the work of the new team. For convenience, I first selected the Large Icons mode, which are displayed as thumbnails.

Display files as thumbnails

Then I selected Enable / Disable Thumbnails in the context menu and got the following result - instead of thumbnails, I saw the icons of Adobe Photoshop, the introductory 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. For more convenience, the author of the original example suggests using ready-made REG-files (togglethumbs.reg) and deleting (undo.reg) sections for a new team, as well as a ready-made script (togglethumbs.vbs). I'd 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 you do not need to clutter 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 location more accessible to the user.

Deleting the contents of a folder without deleting the folder itself



Almost similarly added its own command and in the context menu of the 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 for deleting the contents of the folder without deleting the folder itself. Those. you do not have to open the folder, select all files and press the Delete key, just select the Delete folder contents command. I modified the example a little to make it more organic on the Russian version of Windows.

To do this, add the DeleteFolderContent subsection to the HKEY_CLASSES_ROOT \ Directory \ shell section and create in it the string parameter MUIVerb with the string Delete the contents of the folder . Further, in the DeleteFolderContent section, we create a subsection of the command and in its default parameter we write the line:

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


Everything is ready and you can use an example.

Conclusion



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

As you can see, you can independently configure the context menu of the Explorer. It all depends on your imagination. If you need additional information about the registry settings, you can download the Windows Registry online guide 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 out that many parameters were outdated and it was time to remove them from the directory. But, since the number of users of Windows XP is still large, I decided to create a kind of a settling page , where I will dump the old parameters.

PS Strictly speaking, the methods of setting the context menu in Explorer are available in other versions of Windows, including Windows XP. But, I have long since switched to Windows 7, so I’m posting this post on this blog.

Source: https://habr.com/ru/post/79443/


All Articles