{"id":7613,"date":"2012-05-16T07:00:00","date_gmt":"2012-05-16T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/05\/16\/sure-we-do-that-context-menu-edition\/"},"modified":"2012-05-16T07:00:00","modified_gmt":"2012-05-16T07:00:00","slug":"sure-we-do-that-context-menu-edition","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20120516-00\/?p=7613","title":{"rendered":"Sure, we do that: Context menu edition"},"content":{"rendered":"<p>A customer <a href=\"http:\/\/blogs.msdn.com\/b\/aaron_margosis\/archive\/2004\/06\/23\/163229.aspx#1370794\"> reported a problem that occurred only when they installed a particular application<\/a>. If they uninstalled it, then the problem went away. After installing the application, the &#8220;Run As&#8221; context menu option stopped working. The customer didn&#8217;t provide any other details, but we were able to make an educated guess as to what was going on.\n A common programming error in context menu extensions occurs in extensions which add only one menu item. These extensions ignore the parameters to the <code>IContextMenu::InvokeCommand<\/code> and simply assume that the only reason the method can be called is if the user selected their menu item. After all, if you have only one invokable item, there&#8217;s no need to figure out which one the user selected, because you have only one to begin with!\n The problem is that a context menu extension can be invoked not because the user selected an item under its control but because a verb is <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/11\/26\/270710.aspx\"> being invoked programmatically<\/a>, and each handler is being asked, &#8220;Do you know how to do this?&#8221;\n The result is that the context menu host calls the extension to say, &#8220;If you know how to do <code>runas<\/code>, then please do so,&#8221; and the the extension says &#8220;<a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/02\/11\/71307.aspx\">Sure, we do that<\/a>&#8221; and starts doing its thing. If you are unlucky and the grabby extension is asked the question before the actual <code>runas<\/code> extension, the <code>runas<\/code> command winds up being hijacked by the grabby extension.\n (This is the same mistake that causes <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/02\/02\/66160.aspx\"> the Copy To and Move To commands to behave strangely if you add them to the context menu<\/a>: They assume that the only reason they are invoked is that the user invoked their command, because they weren&#8217;t designed to be hosted by context menus to begin with! They were designed to go into the toolbar, and the toolbar hosting code never invoked commands by name. It&#8217;s like taking a ladder and using it as a bridge between two tall buildings. Sure, you can now cross from one building to another, but you also run a serious risk of falling to your death.)\n A variation on the initial problem is &#8220;I found that after installing a particular program, I can&#8217;t run anything from the Start menu.&#8221; I know of at least two programs which install context menu extensions which steal the &#8220;open&#8221; command on executables.\n This problem is sufficiently prevalent that there is a <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en-US\/w7itproui\/thread\/6a138e65-2834-41ac-bd40-c2344e20b824#209450a5-e1d2-4f3d-bd0f-076e9d7de315\"> special compatibility flag that can be set on a shell extension<\/a> to say, &#8220;This is a grabby shell extension that steals commands. Never ask it if it supports anything, because it will always say yes!&#8221;<\/p>\n<p> Notice that the &#8220;MoveTo CopyTo Context Menu&#8221; is on the list, which I find interesting because MoveTo\/CopyTo was never meant to go on the context menu in the first place. Going back to our analogy, it&#8217;d be as if the ladder company issued a safety bulletin to warn people of problems that can occur if you use it as a bridge between two tall buildings! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer reported a problem that occurred only when they installed a particular application. If they uninstalled it, then the problem went away. After installing the application, the &#8220;Run As&#8221; context menu option stopped working. The customer didn&#8217;t provide any other details, but we were able to make an educated guess as to what was [&hellip;]<\/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":[104],"class_list":["post-7613","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-tipssupport"],"acf":[],"blog_post_summary":"<p>A customer reported a problem that occurred only when they installed a particular application. If they uninstalled it, then the problem went away. After installing the application, the &#8220;Run As&#8221; context menu option stopped working. The customer didn&#8217;t provide any other details, but we were able to make an educated guess as to what was [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7613","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=7613"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7613\/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=7613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=7613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=7613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}