Archive: SetShellVarContext on-the-fly ?


SetShellVarContext on-the-fly ?
  Can I start a section with

SetShellVarContext current
Then change it later on (in same section) to
SetShellVarContext all
Then change it again to
SetShellVarContext current
?

The goal is to place some shortcuts on the Start Menu of the Administrator only, then place some items on the Start Menu of All Users, then restore ShellVarContext back to current.

I just tried that and it didn't work for me. So either there is an inherent limitation of which I didn't know or I am doing something wrong.

If the latter, any idea what could possibly go wrong in simple code like this?
SetShellVarContext all

CreateShortCut "${D_STARTMENU}\\MyApp.lnk" "myapp.exe"
>SetShellVarContext current
>

Did you define D_STARTMENU somewhere?
That define will not change based on SetShellVarContext.
Use $SMPROGRAMS instead (See chapter 4.2.3 in the NSIS manual)


Originally posted by jpderuiter
Did you define D_STARTMENU somewhere?
Yes I did. Thank you for the tip. I changed the above to:

SetShellVarContext all 

CreateShortCut "$SMPROGRAMS\${D_COMPANY}\${D_PRODUCT}\\MyApp.lnk" "$PROGRAMFILES\${D_COMPANY}\${D_PRODUCT}\\myapp.exe"
>SetShellVarContext current
>
But this still doesn't work.

Interestingly enough, I have no such problem with SetOutPath.

Did changing SetShellVarContext on the fly ever worked for anyone?

Thanks.

Update: If I change:


CreateShortCut "$SMPROGRAMS\${D_COMPANY}\${D_PRODUCT}\\MyApp.lnk" "$PROGRAMFILES\${D_COMPANY}\${D_PRODUCT}\\myapp.exe" 

To:
CreateShortCut "$SMPROGRAMS\\MyApp.lnk" "$PROGRAMFILES\${D_COMPANY}\${D_PRODUCT}\\myapp.exe" 

It works.

Strange. I know that ${D_COMPANY} and ${D_PRODUCT} are defined and valid. Why is it behaving like this?

Problem solved. :)

What was missing is the CreateDirectory statement before the CreateShortCut:

CreateDirectory "$SMPROGRAMS\${D_COMPANY}\${D_PRODUCT}" 

jpderuiter, thank you again for the clue that led to the solution.