Archive: Windows 7 registry startup problem.


Windows 7 registry startup problem.
I am using NSIS and I use WriteRegStr to make my program startup when windows starts. It works fine on Win XP and in Win 7 as admin (haven't tested Vista), but in Win 7 with a normal user the registry key doesn't get added, I don't get any UAC windows or anything like that, the key just doesn't get added into the registry.

I use this on the .nsi:

WriteRegStr HKEY_CURRENT_USER "Software\Microsoft\Windows\CurrentVersion\Run" "ProgramName.exe" "$APPDATA\MyProgramFolder\ProgramName.exe"

How can I make it work on Win 7 with a normal user?


You don't need elevated rights for writing to the HKEY_CURRENT_USER branch, I think. But if you added "RequestExecutioLevel admin" to your installer (or did not use "RequestExecutioLevel" at all), then your installer will get elevated when it is started. For "restricted" (no-admin) user accounts this means that UAC will ask for Admin login credentials when the installer is run. The installer will then run under the Admin account. So in this situation HKEY_CURRENT_USER will probably refer to the Admin's registry key, instead of the registry key of the "restricted" user who originally ran the installer. You can't use HKEY_LOCAL_MACHINE to add your app to the Autostart for all users?


I use RequestExecutionLevel user, shouldn't I be able to write that reg key? (without UAC prompt)


Originally posted by uixza
I use RequestExecutionLevel user, shouldn't I be able to write that reg key? (without UAC prompt)
If you explicitly use "RequestExecutionLevel user" your installer won't be elevated.

You still should be able to write to the HKEY_CURRENT_USER branch (because that key doesn't require special permissions) and, as no elevation takes place, that key should refer to the account of the user who ran the installer.

I think you should monitor the installer with ProcessMonitor and check whether the Registry access fails (and why).

The following code works for me:
http://pastie.org/private/8r3wdvbj9krxbwksoxaa

Tested with an Admin account and with a limited (guest) account, on Windows 7.


You might find UAC is blocking writing to that registry key to prevent malware. On Windows 7, many keys are protected in the same way (changing the ACL has no effect). The only way to safely write to these keys is from a Windows service (SYSTEM account).

How about putting a shortcut to your program in $SMSTARTUP instead. Your user will receive a UAC prompt when the application runs if UAC is enabled though.

Stu