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

Raymond Chen

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"

0 comments

Discussion is closed.

Feedback usabilla icon