How can I register my context menu command for all file types *except* one, or other complex conditionals?

Raymond Chen

We saw that you can register your context menu under * to make it apply to all files. But what if you want it to apply to all files except one? For example, your command might be “Convert to Widget” but you don’t want it to appear for .widget files because that would be redundant.

I mentioned how to do this as an afterthought in an earlier discussion of advanced context menu registration, but I’m going to elevate to its own topic because it’s probably even more useful than the base article!

Starting in Windows 7, you can conditionalize your context menu declaratively. This is explained in the documentation for context menus in the section Getting Dynamic Behavior for Static Verbs by Using Advanced Query Syntax. Let’s try it out. Of course, I don’t actually have a “Widgetizer” program, so I’ll just use Calc.

[HKEY_CLASSES_ROOT\*\shell\Widgetize]
"AppliesTo"="NOT System.FileExtension:=.widget"

[HKEY_CLASSES_ROOT\*\shell\Widgetize\Command]
@="calc.exe"

The Widgetize command appears only for files whose extension is not .widget.

You have access to the shell property system and Advanced Query Syntax here, so you can create more complex conditionals. Here’s how you can Widgetize only files that are smaller than 32KB, and ignore zero-byte files.

"AppliesTo"="System.Size:1..32kb AND NOT System.FileExtension:=.widget"

0 comments

Discussion is closed.

Feedback usabilla icon