0

I'm creating a Windows application that needs to add an entry to the Send-To explorer context menu, and needs to do so for all users. Since the Send-To folder is specific for each user, with no common folder for all users, I'm left with two choices:

I can go over all user profiles, as well as the default user profile, find the SendTo folder and add the shortcut to it. This will ensure the shortcut is deleted during uninstall.

Or, I can make sure the shortcut is in the SendTo folder each time a user logs in (by adding my application to the start-up folder of all users). This will make my life a lot easier during installation, but when the application is uninstalled, all those shortcuts will not be removed.

So either way, I need a way to find the SendTo folder of all users. I can scan HKEY_USERS and find the SendTo folder of each user (it might not be in the default location, the user can move it), but how do I find out the user profile's root folder? The registry has something like %USERPROFILE\AppData\Roaming... for the SendTo folder. How can I figure out what %USERPROFILE% is for another user?

Thanks.

zmbq
  • 38,013
  • 14
  • 101
  • 171
  • 1
    You're off on the wrong foot, because `HKEY_USERS` will not contain the profiles for all users. Only the users that happen to be logged on right now. (There's no point loading the profile of a user who is not logged on.) And don't try looking for profiles of users who aren't logged on, because doing so can corrupt roaming profiles. – Raymond Chen Sep 02 '12 at 20:15
  • Instead, configure Windows to run an executable whenever a user logs in. Add the entry from that executable, if it hasn't already been created. – Harry Johnston Sep 03 '12 at 02:10
  • That is an option, but I need to remove all the entries during an uninstall. I'll probably need to create a writable-by-all file in ProgramData and update it every time I add an entry. – zmbq Sep 03 '12 at 05:10
  • 2
    Tampering with profiles of users who are not logged on is going to corrupt the profile. And what if the profile is kept on a server you don't have access to? (Roaming profile scenario.) – Raymond Chen Sep 04 '12 at 14:09
  • 1
    I hate to think of the potential security consequences. If someone adds an entry to your writable-by-all-file saying that your install created a file named `c:\boot\bcd` is your uninstaller going to cheerfully delete it? – Harry Johnston Sep 04 '12 at 20:07
  • @Harry: Ooooh, very good point! I'll just add the folder names, then, and remove the hard-coded shortcut filename in that path. It *will* allow people to delete a file called "DoThisOrThat", but I doubt that is a real security risk. – zmbq Sep 05 '12 at 04:47

2 Answers2

0

You can create a custom action inside MSI, which will go through all user profiles and remove your shortcuts from SendTo folder. All users profile you can find, just scan all folders in %systemdrive%\Users folders in Windows7 (Vista), or Documents and Settings in Windows XP.

Or you can use ActiveSetup mechanism for this purpose, create some script (application) which remove your shortcut from SendTo folder, when user will log in to system next time.

Igor Shenderchuk
  • 698
  • 4
  • 12
  • I can't go over the Users folder, because users may move parts of their profile somewhere else (you can move the SendTo folder anywhere you want by just dragging it). Removing the entry once per each user when they log on is a good idea. – zmbq Sep 05 '12 at 04:51
0

Easier approach: use the launch sequence of the exe itself to check whether the shortcut it present on launch, and create it if not.

Uninstall for all users is best handled using ActiveSetup which will run "something runnable" once for each user logging onto the machine. In your case a simple batch command could do the job.

If you do chose this uninstall approach, you must make sure that your msi installer checks for this uninstall key and deletes it on install - otherwise you have a delete operation scheduled for the shortcut the next time a user logs on.

Also keep in mind that each install should use a different entry in ActiveSetup to ensure that the shortcut creation is re-run for a user who has had it uninstalled already. This last part might be slightly incomprehensible before you read more about ActiveSetup: http://www.etlengineering.com/installer/activesetup.txt

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • OK, thanks, I'll see what's easier - using ActiveSetup as you and @Igor suggested, or going over the list shortcuts I created over time and delete them. The first is more resilient, since it will work if people move their user folder after my program is installed. – zmbq Sep 06 '12 at 05:42
  • I am not sure, but I think there are elevated rights issues with ActiveSetup in later versions of Windows. – Stein Åsmul Mar 25 '14 at 02:20