2

I have a Visual Studio 2013 Windows Forms solution with a setup/installer project (VB.NET 4.5 and Windows Installer 4.5).

I have the installer adding a Start Program folder and item, ie, "Start/All Programs/My Company/Application Name".

The installer works pretty much as advertised except that the context menu doesn’t show several items which I would expect to see.

Here’s a "normal" Program item context menu (for Skype, say) on the left and the one for my application on the right:

Context menu comparison

Note the absence of "Run as Administrator", "Open file location", "Pin to Start Menu", etc.

I looked further and if I compare the properties of each Program Menu item, I see that Skype is targeting an explicit ".exe" while my own is targeting what I expect is a whole Program Group (Skype on the left, my application on the right):

Properties comparison

Note also, that I can’t edit Target.

Now, if I manually add my application's ".exe" to the Program Group, the properties and context menu appear the same as for Skype:

Exe Properties and context

So then I checked the Windows Installer shortcut setting in the installer project's File System settings. As far as I can determine, it only allows me to create a shortcut to the solution's Primary Output, and I can’t explicitly shortcut the KeyOutput ".exe".

Can anyone shed any light on this? Am I missing something obvious?

UPDATE: To clarify what I need, I would like the installer to create a Program Menu item shortcut as per the Skype example, with all of the same context menu options.

UPDATE: After making Stein's suggested MSI change using Orca, validation fails with a couple of errors:

ICE43 ERROR Component 'C__667B7EAE74690565610625BA20DE4CEE' has non-advertised shortcuts. It should use a registry key under HKCU as its KeyPath, not a file. ICE57 ERROR Component 'C__667B7EAE74690565610625BA20DE4CEE' has both per-user and per-machine data with a per-machine KeyPath.

(There is an additional warning unrelated to the manual change:

ICE90 WARNING The shortcut '_2B5AE78F623048DC8EDAB2174FC1AB82' has a directory that is a public property (ALL CAPS) and is under user profile directory. This results in a problem if the value of the ALLUSERS property changes in the UI sequence.

This can be resolved by further manually changing the key to include, say, a lower-case, eg _2b5AE78 ...)

Unfortunately, I've found that when using the modified MSI more often than not, the Program Group isn't actually created at all. Initially, it seemed to work, but thereafter, not. So I've reverted to the unmodified MSI and just sucked up the context issue as it's really not worth the pain.

SteveCinq
  • 1,920
  • 1
  • 17
  • 22

1 Answers1

3

What you describe is an advertised shortcut versus a standard shortcut (a lot of info on MSI shortcuts). An advertised shortcut is a Windows Installer functionality - and they are unique in the sense that they actually point to a product feature (a feature in an MSI package), and not directly to a file. As such I suppose they are handed differently by the shell extension set up to handle shortcut files (*.lnk files).

In very broad terms: advertised shortcuts are central to MSI's "install on demand" features and also trigger an MSI key-path check on invocation (an installation integrity check) - which can trigger self-repair if the product in question is not correctly installed.

The shell handling of *.lnk files is defined in: HKEY_CLASSES_ROOT\.lnk\

Holding down SHIFT and then right clicking the advertised shortcut should bring up more options - such as run as administrator. I think it is the shell itself (%SystemRoot%\system32\shell32.dll) which handles *.lnk files.

We can't really tell what you need from the description you provide. Perhaps you just need the run as administrator option? Maybe not, but if you do, I guess there are a few options:

  1. Just use a regular shortcut (set the advertised attribute for the Shortcut element in your WiX project to "no"). This should bring up a "normal" context menu for the shortcut after installation.

  2. Rely on the SHIFT + right button mouse click described above to show run as administrator when you need it - if this is what you are after.

    • This essentially shows menu entries that are normally hidden and marked as "Extended" in the registry itself, or is marked as such in the compiled shell extension handler's codebase.
    • You can add your own shell extension menus that simply trigger command lines - no compiled shell extension handler necessary. You can even add sub-menus (cascading) and set them to show only on SHIFT + right-click (plus various other options). A digression, but just wanted to mention it.
  3. If you always need admin rights I suppose you could require admin rights via the application manifest? Generally very frowned upon these days, but possible: How do I force my .NET application to run as administrator?

    • This elevation will work for administrators, but not for regular users (non-admin users) - they can't elevate to admin rights.
    • Regular users would need to input admin credentials (for an admin account) to be able to run with admin rights.

To post-process a compiled MSI to disable an advertised shortcut:

  1. Open the MSI with Orca (or another capable tool).
  2. In the File table, get the file ID from the first column. For example something like _55E33B8404377A30ACD2C521F357BF91
  3. In the Shortcut table, set the Target field to: [!_55E33B8404377A30ACD2C521F357BF91].
  4. Save and test install.
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • Hi Stein, thanks for your answer. What I'm looking for is for the installer to create a Program Item shortcut like the Skype on - with all of the context menu items shown in the question. It's not so much about running as Administrator, more about giving the user the option to *Pin To Start Menu*, etc. BTW, the SHIFT key option does bring up more context men items but not all of them. – SteveCinq Mar 05 '18 at 23:35
  • I guess a regular shortcut is your option then - just set Advertise to `no` as described in option 1 above. BTW, I do see "Pin to Start" for advertised shortcuts though? And I believe SHIFT shows any menu items marked as "Extended" in the shell handler code. [Compiled shell extension handlers](https://msdn.microsoft.com/en-us/library/windows/desktop/cc144067(v=vs.85).aspx) are pretty complicated - and I am not familiar with their inner workings. You can add your own handlers though, with simple command lines you can invoke for a certain file type - if that is something you want. – Stein Åsmul Mar 05 '18 at 23:52
  • I'm not using WiX, Stein, just a bare-bones Windows Installer/Setup project. There is no *Advertise* option in the shortcut's properties. I'm not familiar with WiX aside from having heard of it but will have a look. (I don't generally create apps that require Start menu availability, so the standard installer is usually fine.) – SteveCinq Mar 06 '18 at 00:10
  • It is possible to "post process" the compiled MSI file - if that is an option for you. I don't have time to test this right now, but essentially it involves changing the Target column of the Shortcut table to point directly to the file in question. I will update the answer above with some quick pointers. – Stein Åsmul Mar 06 '18 at 00:32
  • Thanks Stein. I tried your MSI "hack" and it worked. Though Orca threw some errors, the installation proceeded smoothly, tho there may be some things I should investigate further just in case. But this is really all I need. It seems WiX is quite a sophisticated package, more than I need ATM but make I'll look into it further ATM later time. Thanks again! – SteveCinq Mar 06 '18 at 01:08
  • What were the errors Orca threw? Validation issues? – Stein Åsmul Mar 06 '18 at 16:13
  • Stein, I'll post these in the question as an update. – SteveCinq Mar 07 '18 at 00:40