January 11th, 2016

Creating a shell extension that applies only to files with a very specific name

Today’s Little Program isn’t even a program. It demonstrates how to register a shell context menu command that applies only to files with a specific name.

Let’s say that you want a special context menu command, let’s call it Party!, on any file called party.txt. If invoked, it runs CharMap because everybody knows that CharMap is a total party animal.

Now, if you wanted the command to apply to any text file, you would use the following registration:

[HKEY_CLASSES_ROOT\txtfile\shell\Party!\command]
@="charmap.exe"

But this offers the Party! command on humorless files like readme.txt.

Fixing this is a special case of getting dynamic behavior for static verbs by using Advanced Query Syntax. In this case, we create an Advanced Query Syntax filter that selects an exact file name.

[HKEY_CLASSES_ROOT\.txt\shell\Party!]
"AppliesTo"="System.FileName:=Party.txt"
Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.