I'm trying to start a few applications for the current user only when Windows starts up.

I can accomplish this with the following:

RegistryKey oKey = Registry.CurrentUser.OpenSubKey("Software", true);
oKey = oKey.OpenSubKey("Microsoft", true);
oKey = oKey.OpenSubKey("Windows", true);
oKey = oKey.OpenSubKey("CurrentVersion", true);
oKey = oKey.OpenSubKey("Run", true);
oKey.SetValue("Application 1", "C:\\path\\to\\ap1.exe");
oKey.SetValue("Application 2", "C:\\path\\to\\ap2.exe");

But I'm trying to run this as part of a Visual Studio Installer Project. I've added my custom action, the program starts like it should, and the installer works great in XP.

In Windows 7, the installer gets elevated privileges, and does everything but insert the entries into the registry for the current user. How ever, it does insert the registry entries when ran as a standalone application (outside of the installer project) and it does not get elevated privileges.

The only thing I can figure is that with the elevated privileges, it's trying to insert the entries into the Administrators account instead of the current user? or is there something else I'm missing? and is there another way I can achieve my goal here?

  • could you give me more information? or elaborate your goal please? – VIRA Aug 27 '12 at 18:04
  • 1
    What if you get Registry.LocalMachine.OpenSubKey() ? – wasyl Aug 27 '12 at 18:05
  • You shouldn't need any custom actions to do this. – Christopher Painter Aug 27 '12 at 19:27
  • 1
    You should be adding shortcuts to the user's startup folder instead, which the installer should be able to do easily, and it will create them in the right location and point them back to the install location of your application. – Ken White Aug 27 '12 at 19:31

Is there a reason to not use the startup folder for the user?

More than likely the problem is the user the installer is executing under. If the user isn't the admin the elevated installer will run under the context of the user who elevated the process.

It would be a safer choice to add your application to the startup folder or to add the registry key on first launch.


If the installer is getting elevated permissions, why write the setting to HKCU? Write it to HKLM instead. It will then take effect for all users.

  • HCKU, HKCU same difference! – ja72 Aug 27 '12 at 18:41
  • Yeah, that is an option.. but I was hoping to keep it for the current user only – C0NFUS3D Aug 27 '12 at 18:50
  • 2
    User specific configuration settings are best configured by the application not the installer. – Christopher Painter Aug 27 '12 at 19:00

Your Answer

