- NSIS Discussion
- Win7: Install a prog for user "James" correctly
Archive: Win7: Install a prog for user "James" correctly
aRalf
11th January 2012 16:22 UTC
Win7: Install a prog for user "James" correctly
Hi, we want to install our software for a user James under Win7. Naturally we need admin rights to write into the program_files directory. NSIS first asks for authorization. Then we can only select an admin user and enter his password. From now on NSIS installs everything for this admin user and forgot that we wanted to install for user James at the beginning. After restarting as user James, the files reside in the admin's AppDataPath and James has no rights to write-access the files in AppDataPath.
How can we install a program for user James under Win7, giving him full access rights to the files in his AppDataPath?
Thanks for your help!
Best regards, aRalf
Afrow UK
11th January 2012 18:08 UTC
If it's a per user install then you shouldn't be writing to Program Files. Everything should be in $APPDATA.
Stu
aRalf
12th January 2012 15:29 UTC
The Prog's Exe has to be written into "Program Files" during installation. The user afterwards has to be able to read/write in his $AppData during program run. Unfortunately, during installation the user changes from James to Admin so $AppData for Admin is used, but not for James.
That means any subdirectory in $AppData created during installation is for Admin. Can I switch back to user James during installation to create a subdir in James' $AppData?
Best regards, aRalf.
aRalf
15th January 2012 15:11 UTC
I hope, my question is comprehensible. Is any information missing?
Best regards, aRalf
MSG
15th January 2012 19:51 UTC
The proper way to do this (which is also the easiest way), is simply to let your program create the %APPDATA%\YourApp directory, instead of trying to do it from the installer. When the program is run (as the James user), the %APPDATA% variable will automatically point to the proper directory.
aRalf
16th January 2012 11:42 UTC
This might be the solution. During install I copy everything I need into the Programs dir and later I copy it with the first start of the app into the respective user's AppData dir.
Several users can then reside on the same PC. I do not need to ask "one user or all users?" during install. Every time a new user starts the app, his appropriate data is copied anew into his AppData. For deinstall I write a hint into the registry each time?
Thank you AfrowUK and MSG for your help!
Best regards, aRalf
aRalf
16th January 2012 11:54 UTC
Good idea!
Thanks for your help, Afrow UK and MSG.
I copy everything into the Programs dir during install. Later during first run, I copy it into the appropriate user's AppData dir :up:
I do not need to ask for "one user or all users?", as several users can get their own AppDatas. During every "first run" I write a hint into the registry for the uninstall?
Best regards, aRalf
MSG
16th January 2012 12:19 UTC
Yes, writing a hint into the registry is probably the best solution for uninstall. In the uninstaller, you can use EnumUsersReg to go through every user's HKCU registry hive, to collect all the hints.
Afrow UK
16th January 2012 12:24 UTC
You have three options that I can think of:
1. Enumerate all folders in the uninstaller under the value specified in the HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\ProfilesDirectory value.
2. Enumerate all keys in the uninstaller under HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList and read each ProfileImagePath value.
3. Have your app write their uninstall path (under AppData) to each of the user's registry (HKCU) as you suggest and then enumerate the registry using EnumUsersReg in the uninstaller (bit more long-winded way).
You can't store a list of users in HKLM or Program Files because those locations are read-only for normal users.
Stu
aRalf
16th January 2012 14:36 UTC
Thanks again!
I will check all proposed uninstall ideas :)
Best regards, aRalf
aRalf
18th January 2012 11:09 UTC
Hi again,
unfortunately if I launch the program (with "Exec") directly at the end of the admin-install then the user is still admin. But I want to launch the program as the current user James! Now during direct launch the $Appdata path is the wrong one.
Do I have to drop the "direct launch" feature of NSIS?
Best regards, aRalf
MSG
18th January 2012 11:35 UTC
There are three solutions to this problem.
1) Disable the direct launch option. This is by far the easiest and most reliable solution. Recommended. The Run Now checkbox is a useless feature anyway.
2) Use the ShellExecAsUser plugin. Relatively simple solution, but will not always work. For more information, see this thread: http://forums.winamp.com/showthread.php?t=335435
3) Use the UAC plugin. Most complex solution. Should works in all cases, but only if you use it right.
aRalf
18th January 2012 12:17 UTC
Thank you MSG, we will use your method 1 ;-)