Friday, February 6, 2009

SendTo shortcuts in an MSI

I recently had to repackage a product that, amongst other things, created a "Send To" shortcut.

The Send To menu.

If you right click on a file or folder you get a context menu with "Send To" as one of the options. Then if you select "Send To" a submenu pops open and you are presented with several choices. Most of the options will create a copy of the file or folder at the target location or open the file in an application (hint: holding the shift key when selecting will move instead of making a copy).

These options such as "Desktop (Create Shortcut)" or "My Documents" are actually shortcuts that exist in a special hidden folder named SendTo. This folder resides under each user profile on the machine, except for the All Users profile. For some reason (at least on Windows XP) the SendTo context menu has a "Per User" behavior not a "Per Machine" behavior. This special folder does exist for the "Default User" profile, but creating the SendTo shortcut there will only affect new users not the existing users.

So, overall the project seemed pretty straightforward. The only problem was the "Per User" behavior of "Send To", because of client needs all the packages that we build or rebuild are set to ALLUSERS=1 (Per Machine installs), and we can't rely on self healing since there would be no direct way to trigger it.

My solution was to use
Active Setup as a workaround. I added the following to the package: HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\[ProductCode] I then set the default value to [ProductName] and I created two other String values:
  • "StubPath"="msiexec.exe /fs [ProductCode] /quiet"
  • "Version"="1,0"
So the first time a user logs in after this package is installed Active Setup will see that it has not run on them and will run the MSI installing the missing SendTo shortcut.

If there is a better way to deal with this I would like to hear about it.

You can disable the "Send To" functionality with a simple registry change
  1. Launch regedit and go to this key: [HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers\Send To]
  2. Double click on the Default value and remove the data: {7BA4C740-9E81-11CF-99D3-00AA004AE837}

This can be reversed by adding the data back to the default value.

Also if you are interested in various other things that can be done with the "SendTo" menu check out this Lifehacker search.