How to Use Nested Context Menus in MSIX Packages

Written by Alex Marin · July 3rd, 2024 · 8min read

Windows context menus provide a quick way to access different commands, but as application complexity increases, these menus can become cluttered.

Nested context menus group these commands into submenus and hence make it easy for users to quickly locate the one they need.

This article explains the concept of Windows nested context menus as well as their advantages and how to work with them.

NoteWe discuss the Context Menu, particularly focusing on its integration and support within MSIX packaging, in this article too.

What Are Nested Context Menus in Windows?

Windows Nested Context Menu

Contextual pop-up lists that appear when right-clicked on files or folders in Windows are known as context menus. These lists provide shortcuts for various commands structured around the item clicked on.

However, growing applications give rise to complicated contextual pop-up menus which may be packed with lots of choices.

This is where nested context menus come into play.

Nested ones allow the organization of commands in submenus so that you can find what you want without confusion.

The user experience gets enhanced with nested context menus having an organized interface that appears neat.

To rapidly identify functions rather than scroll long lists of options, users go through the submenus.

It makes software more intuitive and user-friendly by reducing cognitive load while increasing efficiency.

ImportantPlease keep in mind that the following information presented about the structure and operation of context menus applies only to Windows OS versions prior to Windows 11.
Starting with Windows 11, the context menu entries will only appear if a Sparse Package is provided and installed.

Now that we know about nested context menus, let’s discuss their structure.

The Structure of Nested Context Menus: Program IDs, Extensions, and Verbs

Understanding Program IDs and Extensions

Every program in Windows has its own unique identifier called Program ID (ProgID).

Each of these ProgIDs is associated with file extensions that define what types of files the program can handle.

For example, while .txt extension can be related to text editors; .jpg or .png extensions might be used by photo viewers.

But what exactly are verbs in this context?

Program ID, Extension, Verbs structure

What Are Verbs in Windows Context Menus?

Verbs are the actions that can be performed on a file or folder, like Open, Edit, Print, etc.

These verbs are what you see when you right-click on a file type.

Nested Context Menu example

These verbs have been defined in the Windows registry which tells the operating system what actions are available for different file types.

In the registry, verbs are located under HKEY_CLASSES_ROOT and then under the shell key.

For example, for .txt files, you would look under HKEY_CLASSES_ROOT.txt\shell.

Each verb is listed as a subkey under the shell key and within each verb key you can specify the command to be executed.

Now that you know where verbs are located in the registry let’s change gears slightly and talk about how this changes with MSIX packages.

How Verbs Work in MSIX Packages

Transition from MSI to MSIX: Handling Verbs

The way we handle verbs has shifted from being stored in the registry to writing them directly into the appxmanifest file with MSIX introduction.

This transfer helps simplify handling associations of files and their corresponding tasks by making it easier and more error-proof.

Verbs in MSIX packages are declared within the uap2:SupportedVerbs section of the appxmanifest file.

This section enumerates all the activities that your application can do. MSIX Packages through centralizing the declaration of verbs in the appxmanifest file improves a more organized and controllable way for handling file associations and actions.

uap2:SupportedVerbs section in the appxmanifest file

How to Enable Context Menus in MSI on Windows 11

Now that we understand how context menus should be created, it’s important to note that all the information I provided regarding the registry only applies to Windows versions prior to Windows 11.

Starting with Windows 11, simply placing the required information in the registry is not sufficient for your context menu to appear, and an MSIX sparse package is required.

An MSIX sparse package acts as a partial repackaging of an application. It allows you to take only certain parts of your app—like the core executable or a few key files—and package them in MSIX format while leaving the rest of the application unchanged.

This approach is especially useful for older, legacy apps or when full repackaging is impractical. Think of it as making the minimal changes needed for modern system integration while preserving most of the app in its original state.

One of the advantages of using an MSIX sparse package is that it integrates with the Windows shell, allowing you to add custom options to the right-click context menu.

When you right-click an app and see options like “Open” or “Run as Administrator”, that is the context menu.

With an MSIX sparse package, you can go a step further and create nested menus, where your main right-click option contains sub-options. So, how do you set this up with an MSIX sparse package?

First, after creating your sparse package, you need to inform Windows about your custom context menu items through registry entries.

The Windows Registry stores configuration settings for both applications and the OS.

For a basic context menu, you would add an entry under `HKEY_CLASSES_ROOT` (which is a part of the registry) and specify the action Windows should take when someone right-clicks on your app.

For example, if you want an option that says “Open with MyApp.”, you’d add something like this to the registry:

HKEY_CLASSES_ROOT\*\shell\YourAppContextMenu

Within this key, you can specify the name of the menu item, the command it should execute when clicked, and other details.

This key is where Windows will look to figure out what to show when you right-click on a file or an app.

Now, if you want to add a nested menu, you can extend this same structure. Under your main context menu item (in this case, `YourAppContextMenu`), you can add sub-commands, like so:

HKEY_CLASSES_ROOT\*\shell\YourAppContextMenu\SubMenu1
HKEY_CLASSES_ROOT\*\shell\YourAppContextMenu\SubMenu1\command

This setup adds an extra layer of options, creating sub-options under your primary right-click menu item.

It’s also important to consider how the context menu is associated with specific file types or even the app’s shortcut.

If you want your custom context menu to appear when the user right-clicks a `.exe` file or a specific file type related to your app, set that association in the registry as well.

Alternatively, link it to the app shortcut, so the options appear when the user right-clicks the icon.

A sparse package is not installed in the traditional sense. It’s registered with the system, which is what allows it to add things like the context menu and other shell extensions. This is super useful because it means your app doesn’t have to be fully packed into MSIX format to take advantage of modern Windows features like the context menu.

After creating the sparse package and adding the necessary registry entries, deploy it or register it using a command like this in PowerShell:

Add-AppPackage -Path "YourSparsePackage.msix"

After that, you should see your custom right-click options appear when you interact with the app or file type associated with your package. It’s a matter of configuring the sparse package in such a way that Windows knows to look for and display those context menu options.

In summary, MSIX sparse packages allow you to integrate modern features like context menus into your app without needing to fully repackage everything. By adjusting the registry and using sparse packaging, you can provide users handy right-click options—like opening a submenu with extra commands—and keep the rest of your app unchanged.

Using Advanced Installer GUI to add nested context menus in MSI and MSIX

Advanced Installer simplifies managing verbs in MSIX packages through a simple and user-friendly interface.

This powerful tool eliminates the need to manually edit the appxmanifest file, reducing errors and saving time.

With Advanced Installer you can easily declare verbs, assign icons, and configure your MSIX packages without digging into the complexities of the appxmanifest file.

Here’s how to manage verbs in your MSIX packages using Advanced Installer.

1. Open Advanced Installer and load your project.

2. Navigate to the "File Associations" section, where you can view and manage the list of extensions your application supports.

3. Add new verbs, assign specific icons, and configure their behavior directly from the user interface.

4. Configure verb behavior: Advanced Installer allows you to specify how each verb should behave. You can set parameters such as the command line, the working directory, and any additional arguments needed for the verb.

Verbs management in Advanced Installer GUI

5. Save and build your MSIX package: Once you've configured your verbs and file associations, save your project and build your MSIX package. Advanced Installer ensures that all settings are correctly applied and included in the final package.

Using Advanced Installer streamlines the process of managing verbs and file associations in MSIX packages.

Here are some key benefits:

  • Efficiency: The user-friendly interface saves time by streamlining complex configurations.
  • Error Reduction: By automating many tasks, Advanced Installer reduces the potential for manual errors.
  • Comprehensive Management: The tool is an all-in-one solution for managing all aspects of your MSIX package from file associations to verb behaviors.
  • Ease of Use: Even if you are new to MSIX packaging, Advanced Installer’s intuitive design makes it easy to get started and efficiently manage your applications.

TipTry out Advanced Installer's Nested Context Menus for MSIX and MSI with a 30-day full-featured free trial.

Video Tutorial

Conclusion

Advanced Installer offers an efficient and simple way to manage verbs in your MSIX packages.

By using nested context menus and a robust UI of Advanced Installer, you can improve workflow productivity, reduce complexity, and enhance users’ experience for application developers.

For more tips and tutorials on software packaging and deployment, subscribe to our blog and stay updated with the latest advancements in the field.

Subscribe to Blog

Written by
See author's page
Alex Marin

Application Packaging and SCCM Deployments specialist, solutions finder, Technical Writer at Advanced Installer.

Comments: