Archive: SetShellVarContext


SetShellVarContext
Hello,

I want to let the user select wether to install the program for the current user only or for all users. I understand that I can use SetShellVarContext to do this.

But I have a problem. Will this also be applicable to ReadRegStr when I read a value in HKCU?

For example,

ReadRegStr $0 HKCU "${SHELLFOLDERS}" "Local Settings"

I need to put some files in a specific shell folder(Local Settings) for each user if the install for all is selected.

If I cannot do this, how can I get the Local Settings folder for each registered user in Windows?

Thanks,
katips:D


I think that if you wish to write to a reg key which will affect all users you should use the 'HKU' root. Not 100% certain of this though.

Vytautas :)


To save a registry value for all users, use HKLM.


Re: SetShellVarContext

Originally posted by katipunero
...I can use SetShellVarContext to do this.

But I have a problem. Will this also be applicable to ReadRegStr when I read a value in HKCU?
No, it won't. You'll have to write two code paths, one for HKLM and one for HKCU. You can also use a simple macro like:
!macro ReadRegStr var key value
StrCmp $ALLORCURRENT all 0 +3 # replace with real check
ReadRegStr "${var}" HKLM "${key}" "${value}"
Goto +2
ReadRegStr "${var}" HKCU "${key}" "${value}"
!macroend

If I uses HKLM and look for the "Application Data" folder, ReadRegStr will return something like:

c:\documents and settings\all users\application data...

But this is not what I need. I need the "Application Data" folder for each user. This is used in the program being installed so I am constrained to it. For example, I need:

c:\documents and settings\user0\application data
c:\documents and settings\user1\application data

Can I know from the registry the shell folders for each user? Or, perhaps, the names of each registered user?

Thanks to all,

katips:D


You can read HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\AppData. The best way is actually using the shell functions and a version of NSIS that supports it should be uploaded to CVS tomorrow. For now, you can call it using System.dll or use the registry key (not recommended by Microsoft).


But using ReadRegStr $0 HKCU "${SHELLFOLDERS}" "Local Settings"
only gives me the shell folder for the current user. I need the shell folder for each users.

Anyway, I will wait until tomorrow for the CVS update. Thanks..

I saw from HKU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders some values for shell folders. I will investigate about it if this can also help me.

Regards,
katips:D


http://nsis.sourceforge.net/archive/...instances=0,44


Oh, you want to enumerate all of the users on the computer... SHGetFolderPath (which is by far not on every system) has an extra parameter hToken which allows you to specify a certain user. You won't be able to do that with today's CVS update. I think it would the easiest if you write a plug-in for this porpuse.

BTW, why put it in each user's folder? If it's for all users, why not put it in the all users' folder? If you want it to be per-user setting, why not just create the folder when the user first uses your program?


Thanks for the help, I will try it...

I am constrained by the program being installed that is why I cannot use the all users' folder even if I want to.

But, I take your suggestion how to make the program works for all users. I think that is the best way to do it.

Regards,
katips:D