Archive: Multiple User Priv. Install


Multiple User Priv. Install
Hi,

I am trying to create an installer that is capable of installing any registry items to either HKLM or HKCU (maybe others down the road). I am aware I could, (everywhere I write to a registry) do something like:

StrCmp $local_machine '1' total_machine
DeleteRegKey HKCU "${PRODUCT_UNIST_KEY}"
Goto skip_total
total_machine:
DeleteRegKey HKLM "${PRODUCT_UNIST_KEY}"
skip_total:

Where $local_machine was a variable populated by a MessageBox response, but I am looking for a cleaner solution. I have tried something like:

DeleteRegKey $local_machine "${PRODUCT_UNIST_KEY}"

Where $local_machine was a variable that contained HKLM or HKCU but I quickly found that those were actually integer like values. Is there a clean way to do the code located above or am I going to have to bite the bullet and do the equivalent of large if/else blocks (in this case goto blocks). Sorry if there is a simple answer to this question as I am new to NSIS.


Use SHCTX instead of HKCU and HKLM. It changes to either HKCU or HKLM according to SetShellVarContext.


Thanks for the response, this works for all the Registry Writes and Deletes, but not for the initial:

InstallDirRegKey SHCTX "${PRODUCT_DIR_REGKEY}"

Since I am to able to use StrCmp outside of a function, and InstallDirRegKey requires that you use it outside of a function I am at a loss as to what should be done.

Any other suggestions?


You can do that manually in .onInit.


I am not quite sure what you mean by "manually" install. I cannot put

InstallDirRegKey

inside on .onInit because that is a function. Is there some directory I should set my path to create this "manually" or something?? Some example code or a pointer to a project that has done what you are describing would be great.

Thanks.


Manually read the registry using SHCTX in .onInit using ReadRegStr. You can't use SHCTX in InstallDirRegKey because you'd have no where to call SetShellVarContext prior to the parsing of InstallDirRegKey. $INSTDIR is set according to InstallDir and InstallDirRegKey before .onInit is called. .onInit is always the very first piece of code of your script called.