{"id":3643,"date":"2023-09-19T09:05:57","date_gmt":"2023-09-19T13:05:57","guid":{"rendered":"https:\/\/www.tmurgent.com\/TmBlog\/?p=3643"},"modified":"2023-09-19T13:34:43","modified_gmt":"2023-09-19T17:34:43","slug":"the-strange-new-twists-in-notepad-context-menu","status":"publish","type":"post","link":"https:\/\/www.tmurgent.com\/TmBlog\/?p=3643","title":{"rendered":"The Strange New Twists in Notepad++ Context Menu"},"content":{"rendered":"\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.tmurgent.com\/TmBlog\/wp-content\/uploads\/2023\/09\/chameleon-pencil-200.png\" alt=\"Notepad++ logo\" width=\"200\" height=\"130\" align=\"left\" \/>The wicked cool open-source application Notepad++, a free XML editing tool, is an example of an app commonly deployed in enterprises that not only has a shortcut to start the application, but also uses the Windows file explorer File Type Associations\u00a0to allow the end user to launch Notepad++ from any file on the system by right-clicking.<\/p>\n<p>This app has been difficult for many to package into MSIX, due to an issue with the Context Menu missing.\u00a0 Last year we worked out two solutions for this issue.\u00a0 The better solution involved using a new type of application extension that is only available on Windows 11.\u00a0 For Windows 10 deployments, we recommended converting the Context Menu into a Shell Menu as the solution.<\/p>\n<p>But now in version 8.5.7 of Notepad++, the developer did some bizarre things that are causing us issues again.<\/p>\n<p><strong>Background<\/strong><\/p>\n<p>But first some background.<\/p>\n<p>When it comes to File Type Associations, Windows has two types of file types.\u00a0 The standard ones are for files that have names that end in a file type extension, such as foo.xml. The special ones are for things like folders, drive, and a special case &#8216;*&#8217; that means for any type of file.\u00a0 Notepad++ uses the special &#8216;*&#8217; file type for its registration.<\/p>\n<p>As I wrote in The Application Book, Windows has two choices when it comes to implement the registration of the FTA, the <em>Shell Integration<\/em> method and the <em>Shell Extension<\/em> method.\u00a0<\/p>\n<ul>\n<li>The <em>Shell Integration<\/em> method is the simplest for the developer.\u00a0 In the registry, under the file type the developer adds a key called &#8220;shell&#8221;, and under there the developer can add verbs and the command line to be used.\u00a0 These verbs will then appear in the pop-up menu whenever the user right clicks on a file of that file type.<\/li>\n<li>The <em>Shell Extension<\/em> method is more dynamic, and requires the developer two write a special in-process COM based dll called a Context Menu Shell Extension.\u00a0 This gets registered under a ShellEx key under the file type, and here the Context Menu handler is defined by its COM CLSID GUID.\u00a0 The COM CLSID is also registered, which allows the dll to be found and loaded by the file explorer when needed. In essence, the file explorer asks the context menu handler &#8220;what verbs to you want me to display and what command to run if chosen&#8221;.\u00a0 This allows the handler to consider the context of the request and supply different lists for different situations.<\/li>\n<\/ul>\n<p>There are some additional options, like ProgIDs, that I am skipping over in the above description, but it is good enough definition for our situation.<\/p>\n<p><strong>What Notepad++ did before<\/strong><\/p>\n<p>Notepad++ has, for quite some time, implemented a Shell Extension Context Menu.\u00a0 The handler, however, always returns the same list, which by default is a single item to &#8216;Edit in Notepad++&#8217;.\u00a0 The app does provide an xml file to customize that, but most folks use this default.\u00a0 If you aren&#8217;t customizing that, a Shell Integration for a verb would have sufficed, been more efficient, and would not have caused us the packaging headaches.<\/p>\n<p>The problem originally was that the special file type &#8216;*&#8217; was not supported in the MSIX schema set.\u00a0 This was later addressed in a schema update which solved the problem, but only for systems running Windows 11.\u00a0 So, we were fixing the package for Windows 11 by updating the AppXManifest to get the full feature, but for Windows 10 deployments our suggested method was to get rid of the shell extension and create your own Shell Integration verb (note: this also works for Windows 11).<\/p>\n<p><strong>What Notepad++ 8.5.7 did<\/strong><\/p>\n<p>It turns out that not only were people repackaging Notepad++ for deployment in MSIX having an issue, but that the native application installation on Windows 11 was also having an issue with the shell extension working as expected.<\/p>\n<p>So in version 8.5.7 the primary author re-implemented the registration in a strange way, one that I&#8217;ve never seen before.\u00a0 And then he added another bizarre twist to get it working on Windows 11!<\/p>\n<ol>\n<li>First, the new installer uses a little-known and undocumented (as far as I can find) third method to perform the Shell Extension registration.\u00a0 This method uses the Shell key instead of the ShellEx key, but then defines the COM CLSID GUID in a special registry value named <strong>ExplorerCommandHandler<\/strong>.\u00a0 Of course the COM CLSID must still be added to the registry too.\u00a0 Not only had I never noticed this used before, but the Microsoft MSIX Packaging Tool didn&#8217;t know what this was either and ignored it.\u00a0 By the way, so does the Microsoft App-V Sequencer (which is how this issue was first reported to me).<\/li>\n<li>Now comes the second bizarre thing done.\u00a0 The native exe installation of Notepad++ 8.5.7 drops down a file called NppShell.msix next to the NppShell.dll file which is the Context Menu Handler.\u00a0 Then it tries to silently install this <strong>MSIX<\/strong> file.<\/li>\n<\/ol>\n<p>The MSIX file dropped down is what is known as a &#8220;<strong>sparse<\/strong>&#8221; msix file, which means that it references things that are not in the package.\u00a0<\/p>\n<table class=\" aligncenter\" style=\"width: 90%; border-collapse: collapse; border-style: solid; border-color: #031954; background-color: #b3d8f5;\">\n<tbody>\n<tr>\n<td style=\"width: 100%;\">Note: I&#8217;ve never heard of a sparse msix file used the way this one is being used. It normally is used in very large games that want to minimize the initial download size and then download new levels as the game goes on.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In fact, the msix package dropped on to the system here pretty much consists of the AppXManifest file and no binary components.\u00a0 It is manifested to only install on Windows 11, so if you natively install the app on Windows 10 this MSIX package will silently fail to install and the traditional registration will be used, which works.\u00a0 On Windows 11, that doesn&#8217;t work, so once the MSIX package is installed, you get the context menu.\u00a0\u00a0<\/p>\n<p>So, what is in this special 68kb msix file?\u00a0 Just enough to register the ContextMenu &#8211; exactly as we have been doing in our repackaging.<\/p>\n<p><strong>But how does this affect repackaging the entire app into MSIX?<\/strong><\/p>\n<p>Well, by default, our package will contain the extra msix package file, but it is ignored.\u00a0 It doesn&#8217;t matter if it was installed while in a packaging monitoring mode as those areas of the system are ignored. And since the registration of the Shell Extension is now under the Shell key, neither the Microsoft MSIX tool, nor my own tooling, knows to look for it there to add the extension into our full package MSIX file.<\/p>\n<p><strong>What can we do about this?<\/strong><\/p>\n<p>I am adding code to TMEditX to detect and fix this shortcoming (it will be in the release that follows the current 3.5 release).\u00a0 For anyone that can&#8217;t wait for that or are using other tools (like the App-V Sequencer), I recommend just dropping back to the old Shell Integration verb method of solving the problem.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The wicked cool open-source application Notepad++, a free XML editing tool, is an example of an app commonly deployed in enterprises that not only has a shortcut to start the application, but also uses the Windows file explorer File Type Associations\u00a0to allow the end user to launch Notepad++ from any file on the system by&hellip; <a class=\"more-link\" href=\"https:\/\/www.tmurgent.com\/TmBlog\/?p=3643\">Continue reading <span class=\"screen-reader-text\">The Strange New Twists in Notepad++ Context Menu<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[53,57],"tags":[52],"class_list":["post-3643","post","type-post","status-publish","format-standard","hentry","category-msix","category-packaging","tag-msix","entry"],"_links":{"self":[{"href":"https:\/\/www.tmurgent.com\/TmBlog\/index.php?rest_route=\/wp\/v2\/posts\/3643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tmurgent.com\/TmBlog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tmurgent.com\/TmBlog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tmurgent.com\/TmBlog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tmurgent.com\/TmBlog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3643"}],"version-history":[{"count":4,"href":"https:\/\/www.tmurgent.com\/TmBlog\/index.php?rest_route=\/wp\/v2\/posts\/3643\/revisions"}],"predecessor-version":[{"id":3647,"href":"https:\/\/www.tmurgent.com\/TmBlog\/index.php?rest_route=\/wp\/v2\/posts\/3643\/revisions\/3647"}],"wp:attachment":[{"href":"https:\/\/www.tmurgent.com\/TmBlog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tmurgent.com\/TmBlog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tmurgent.com\/TmBlog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}