Registering Shortcut Menus in Windows

I was working on something whose UI involves right-click menu. Do not have the time to chew through Microsoft docs so I assembled the informations I gathered online.


  1. You edit the Windows Registry.
  2. You don't need to call Win32 API to edit the registry (if you can accept your program asking users for permission), but a Win32 API is provided.
  3. You can generate a .reg file and execute regedit.exe /S [file.reg]. .reg file is very similar to an .ini file so it should be easy.
    1. You start with Windows Registry Editor Version 5.00 and a blank line. If you need to support OSes older than Windows 2000, then it's REGEDIT4.
    2. Each section should be separated by a blank line or else it wouldn't register.
    3. To delete a key, add - before the key path, so it's [-PATH] instead of [PATH] (which is adding/editing the key).
  4. The "root path" for shortcut menu is:
    # for any file, global. "*" matches any extension name; you can also add to the corresponding extension name.
    # for directory, global.
    # for right-clicking in directory background, global.
    # for any file, local.
    # for directory, local.
    # for right-clicking in directory background, local.
    # for submenu item. (explained later)
  5. To change the label of the menu-item, edit the default value of the corresponding key. To add a command for executing when selecting the menu-item, add a Command subkey and edit the default value. e.g. to add a menu item for directory background locally with name MyCommand, label "Execute notepad" and command "notepad.exe", you do this:
    @="Execute notepad"

    An icon can be added as well:

    @="Execute notepad"

    The icon path can refer to an .ico (of course), an .exe or a .dll; in Windows .exe and .dll can contain icons and Windows will retrieve the icon from there.

    You can also control the position of the menu item to be "Top" or "Bottom" by adding a REG_SZ value with name "Position".

  6. To add a two-level menu, you don't add the Command subkey, but instead add value named MUIVerb (this would be the label) and SubCommands (this would be referring to the submenu items). Icon and Position can also be added.
  7. To add submenu items to a two-level menu, you need to first add those item at the path for submenu items mentioned above, and refer their names (not labels) in the SubCommands field, separated by semicolon ;. To add a separator item, use | instead of command names.
  8. Maybe more than 2 levels of submenu is supported. I haven't tested myself so I'm not sure.


For example, to add a shortcut menu like this:

+ Send this file to Heaven
  + execute command `send-to.exe heaven north-europe`
  + icon `C:\MyFiles\n-europe.ico`
+ Send this file to Hell (Brazil)
  + execute command `send-to.exe hell brazil`
  + icon `C:\MyFiles\brazil.ico`
+ Send this file to Extra Hell
  + icon `C:\MyFiles\china.ico`
  + To Shanghai
    + execute command `send-to.exe extra-hell shanghai`
    + icon `C:\MyFiles\shanghai.ico`
  + ----
  + To Dongxing
    + execute command `send-to.exe extra-hell dongxing`
  + To Shenzhen
    + execute command `send-to.exe extra-hell shenzhen`
  + ----
  + To Yili
    + execute command `send-to.exe extra-hell yili`

The .reg file needed would be:

Windows Registry Editor Version 5.00

@="Send this file to Heaven"

@="send-to.exe heaven north-europe"

@="Send this file to Hell"

@="send-to.exe hell brazil"

"MUIVerb"="Send this file to Extra Hell"

@="To Shanghai"

@="send-to.exe extra-hell shanghai"

@="To Dongxing"

@="send-to.exe extra-hell dongxing"

@="To Shenzhen"

@="send-to.exe extra-hell shenzhen"

@="To Yili"

@="send-to.exe extra-hell yili"

And the .reg file used to delete all this would be:

Windows Registry Editor Version 5.00