Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
Published:
Updated:
Browse All Articles > Add a Custom Command Button to the Windows 7 Explorer Toolbar
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar. In the previous article, we saw how to put the Delete button back there where it belongs. "Delete" is a predefined action, but today, we're going to add a button that you can program to do whatever you want.
Microsoft intentionally left out the familiar "Customize..." option for the Explorer toolbar. They provided a bunch of pre-set toolbars that depend upon the types of files that are in the folder that is being displayed. In any case, they do not (yet) document how to tweak the registry to modify those preset layouts. However, there are enough examples in the existing registry entries to make it possible to do some nifty tweaks without resorting to low-level system programming.
As before, we'll be working with the subkey(s) under the registry key:
In there, you'll find a bunch of GUID items that associate with various types of folders. See part one for more details. We'll again be working with the item that represents "Generic" folder data. This basically means all folders that are not "optimized" as being a "Photo" folder or a "Document" folder or any of the special Shell Namespace folders; that is, it appears above folders that are set to display "General Items."
[step="" title=""]Notice: There are certain dangers in using RegEdit to modify the system registry. Be very careful.
I recommend that you make a backup of your registry before experimenting (I certainly did).[/step]
Add a Custom Command Button to the Explorer Toolbar
Set the permissions: Change the Owner to "Administrators" and set Administrators to have "Full Control" over that registry key.
Add keys, TasksItemsSelected\1 to get to this point:
[step="" title="Note:"]We added the 0 subkey in part one of this article.
If you did not follow along there, then your subkey should be 0 (not 1).[/step]
Next, we add as a subkey, a brand-new GUID that will identify the MyTool button and command. You must use a valid GUID, but any unique GUID-format value will do. I used uuidGen.Exe that comes with Visual Studios to create a GUID, then I tweaked the value a little for fun. In short, I added the subkey:
{BEEFF00D-F51D-11DE-A821-413C56D89593}
The data elements in that new key are:
InfoTip REG_SZ Infotip for MyTool Title REG_SZ MyTool
There are other values you can add, but this is all we need for the purposes of adding a text-only button to the Explorer toolbar. The Title value is the text that will be displayed on the Explorer toolbar.
Below the {BEEFF00D... key, we need to add, in steps,
shell InvokeTask command
And for the final one, change the (Default) value to specify the command to execute.
Here are the RegEdit screens after entering the data:
And here's the RegEdit reference script. Important: The script assumes that we are adding tool# 1, and that tool# 0 is already in place (Explorer won't recognize out-of-sequence tool numbers). AND the permissions must be set before running this script.
[step="" title="PutMyToolOnToolbar.REG"]
Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{5c4f28b5-f869-4e84-8e60-f11db97c5cc7}\TasksItemsSelected][HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{5c4f28b5-f869-4e84-8e60-f11db97c5cc7}\TasksItemsSelected\1][HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{5c4f28b5-f869-4e84-8e60-f11db97c5cc7}\TasksItemsSelected\1\{BEEFF00D-F51D-11DE-A821-413C56D89593}]@="""InfoTip"="InfoTip for MyTool""Title"="MyTool"[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{5c4f28b5-f869-4e84-8e60-f11db97c5cc7}\TasksItemsSelected\1\{BEEFF00D-F51D-11DE-A821-413C56D89593}\shell\InvokeTask\command]@="cmd.exe \"/c c:\\ProgramData\\MyScripts\\MyTool.bat %*\""
[/step]The final line sets a command that will be executed. It can be any program name, such as Notepad.Exe or calc.exe, but in this example, I set it to execute a batch file:
@REM -- Used in the "My Tool" custom Explore Tool bar button@ECHO MyTool program name: %0@ECHO Active folder when clicked: %1@ECHO first file: %2@ECHO second file: %3@ECHO third file: %4@PAUSE
[/step]We have set the options in the registry so that this tool will be available only when there is one or more items selected in the Explorer window (we used the TasksItemsSelected key). When the tool runs, it will receive at least two parameter values.
%1 -- The path of the folder that was being displayed
%2 -- The pathname of the file that was selected.
If you select more than one file before clicking the MyTool button, then the subsequent filenames will be in subsequent parameters.
I have used a simple DOS batch file for illustration, but you'll certainly want to write your own fancy program. If you use a script file (such as a .JS or .VBS script) then you need to specify the program that runs scripts: WSCRIPT.EXE. For instance, setting the command (Default) value to:
// Example JScript file for an Explorer toolbar custom tool.// Argument 0 is the folder that was active.// Arguments 1 - n are full pathnames of selected files// var oArgs= WScript.Arguments;//--------- cycle through the filenames in the dropped selectionfor (var j= 0; j < oArgs.Count(); j++ ) { var sSrcFile= oArgs( j ); WScript.Echo( j + ": "+sSrcFile ); }
Summary
Although Microsoft seems to discourage user-customization of the Win7 Explorer toolbar, it is possible to add buttons -- for both predefined and custom commands -- to that toolbar.
In these articles, we saw how to set the permissions to allow modifications of protected registry settings with RegEdit. And we saw what registry keys to add in order to add new toolbar button and make it perform any user-programmed command. We also looked at how to handle the command-line parameters that will be provided to the custom tool when it executes.
There is much more to to learn about this facet of Windows 7 programming. For instance, I'd like to add a new drop-down menu (instead of just a single button) and I'd like to burn that "Burn" command right off the toolbar. But we'll have to leave that for a future article. I hope you have enjoyed this and perhaps learned a thing or two. Thanks for tuning in!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If you liked this article and want to see more from this author, please click the Yes button near the:
Was this article helpful?
label that is just below and to the right of this text. Thanks!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
Hey, yeh that was great! I am trying to use this new button to shortcut to Context>New>Text Document command, so it creates a new text document unopened ready to be titled, just like the New Folder button. Any ideas how this should be done? Apologies if this is not the place for questions, I'll post to forum as well :)
Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
I got an email regarding this article from a person who neglected to provide his EE member name... It suggested that a valuable custom tool would be one that might be called "Add Folder"
The current mechanism involves: right-click / New... / Folder / type something to rename from "New Folder" (that is, a multiple-step operation). The custom tool would pop up a box to input the folder name and it could set folder attributes and even open a new Explorer window on the folder for immediate use.
It's a good idea. If you have other ideas for useful custom tools, feel free to post them here.
Comments (7)
Author
Commented:here's a list: http://w.e-e.com/bCVjPK
Commented:
Thanks, Nathan
Commented:
Commented:
https://www.experts-exchange.com/Programming/System/Windows__Programming/
Author
Commented:The current mechanism involves: right-click / New... / Folder / type something to rename from "New Folder" (that is, a multiple-step operation). The custom tool would pop up a box to input the folder name and it could set folder attributes and even open a new Explorer window on the folder for immediate use.
It's a good idea. If you have other ideas for useful custom tools, feel free to post them here.
-- Dan
View More