{"id":5323,"date":"2013-02-07T07:00:00","date_gmt":"2013-02-07T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/02\/07\/how-can-i-register-my-context-menu-command-for-all-file-types-except-one-or-other-complex-conditionals\/"},"modified":"2020-12-19T19:45:56","modified_gmt":"2020-12-20T03:45:56","slug":"20130207-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130207-00\/?p=5323","title":{"rendered":"How can I register my context menu command for all file types *except* one, or other complex conditionals?"},"content":{"rendered":"<p>We saw that you can <a title=\"What is the difference between the Folder and Directory (and other special) progids?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20070802-00\/?p=25743\"> register your context menu under <code>*<\/code><\/a> to make it apply to all files. But what if you want it to apply to all files <i>except one<\/i>? For example, your command might be &#8220;Convert to Widget&#8221; but you don&#8217;t want it to appear for <code>.widget<\/code> files because that would be redundant.<\/p>\n<p>I mentioned how to do this as an afterthought <a title=\"Simplifying context menu extensions with IExecuteCommand\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100312-01\/?p=14623\"> in an earlier discussion of advanced context menu registration<\/a>, but I&#8217;m going to elevate to its own topic because it&#8217;s probably even more useful than the base article!<\/p>\n<p>Starting in Windows\u00a07, you can conditionalize your context menu declaratively. This is explained in the documentation for context menus in the section <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/shell\/context-menu-handlers?redirectedfrom=MSDN#getting-dynamic-behavior-for-static-verbs-by-using-advanced-query-syntax\"> <i>Getting Dynamic Behavior for Static Verbs by Using Advanced Query Syntax<\/i><\/a>. Let&#8217;s try it out. Of course, I don&#8217;t actually have a &#8220;Widgetizer&#8221; program, so I&#8217;ll just use Calc.<\/p>\n<pre>[HKEY_CLASSES_ROOT\\*\\shell\\Widgetize]\r\n\"AppliesTo\"=\"NOT System.FileExtension:=.widget\"\r\n\r\n[HKEY_CLASSES_ROOT\\*\\shell\\Widgetize\\Command]\r\n@=\"calc.exe\"\r\n<\/pre>\n<p>The <i>Widgetize<\/i> command appears only for files whose extension is not <code>.widget<\/code>.<\/p>\n<p>You have access to the shell property system and Advanced Query Syntax here, so you can create more complex conditionals. Here&#8217;s how you can Widgetize only files that are smaller than 32KB, and ignore zero-byte files.<\/p>\n<pre>\"AppliesTo\"=\"System.Size:1..32kb AND NOT System.FileExtension:=.widget\"\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Advanced Query Syntax to the rescue.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-5323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Advanced Query Syntax to the rescue.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=5323"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5323\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=5323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=5323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=5323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}