Old 25th September 2011, 22:09   #1
uixza
Junior Member
 
Join Date: Sep 2011
Posts: 2
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?
uixza is offline   Reply With Quote
Old 25th September 2011, 22:36   #2
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
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?

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 25th September 2011, 23:45   #3
uixza
Junior Member
 
Join Date: Sep 2011
Posts: 2
I use RequestExecutionLevel user, shouldn't I be able to write that reg key? (without UAC prompt)
uixza is offline   Reply With Quote
Old 26th September 2011, 00:04   #4
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Quote:
Originally Posted by uixza View Post
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).

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 26th September 2011, 00:15   #5
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
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.

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 29th September 2011, 10:22   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump