Archive: SetShellVarContext in Vista


SetShellVarContext in Vista
I'm well confused about how SetShellVarContext works on Vista.

I have an installation script which does NOT have a SetShellVarContext in the install section. I would have thought that this would install just for the current user, but it installs for all users, including a Start>AllPrograms menu entry and a destop shortcut in all user accounts.

Here's the section:

Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "Myprog.exe"
CreateDirectory "$SMPROGRAMS\Myprog"
CreateShortCut "$SMPROGRAMS\Myprog\Myprog.lnk" "$INSTDIR\Myprog.exe"
CreateShortCut "$DESKTOP\Myprog.lnk" "$INSTDIR\Myprog.exe"
SectionEnd
Having unexpectedly got an installation in all user accounts I found that the only way to get the Start>AllPrograms menu to be uninstalled/deleted in ALL of the user accounts was to have "SetShellVarContext all" in the uninstall section. BUT the desktop shortcuts were NOT deleted! The only way I could get the desktop shortcuts deleted was to put them in a separate unsinstall section which did NOT have a SetShellVarContext, like this:

Section un.desktop
Delete "$DESKTOP\Myprog.lnk"
SectionEnd

Section Uninstall
SetShellVarContext all
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\Myprog.exe"

Delete "$SMPROGRAMS\Myprog\Uninstall.lnk"
Delete "$SMPROGRAMS\Myprog\Website.lnk"
Delete "$SMPROGRAMS\Myprog\Myprog.lnk"

RMDir "$SMPROGRAMS\Myprog"
RMDir "$INSTDIR"

DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
So the above was the only way I could get the desktop shortcuts and the Start>AllPrograms menu to be removed for all users.

This doesn't make sense. I would have expected no SetShellVarContext to cause install/uninstall only for the current user, and "SetShellVarContext all" to install/uninstall for all users.

But the above seems to defy this logic.

Can anyone explain what's going on here?

After a closer look, it seems that the install section is putting the "All Programs" menu entry into the all users area

C:\ProgramData\Microsoft\Windows\Start Menu\Programs

but it is putting the desktop shortcut into each user's own desktop area - e.g.

C:\Users\John\Desktop

That would explain why the uninstall sections need "SetShellVarContext all" to get rid of the All Programs menu, but doesn't need a SetShellVarContext to get rid of the desktop shortcut.

The question is why did the install section choose to put the All Programs menu into the ALL users area without being told to; and why did the install section put a desktop link into the desktop of every user?


http://forums.winamp.com/showthread....55#post2064155

http://nsis.sourceforge.net/Shortcut..._Windows_Vista


Thanks. I removed all of the SetShellVarContext statements from my script and added a "RequestExecutionLevel admin" statement at the top of my script.

I am logged in as an ordinary user and I run the installer - this cause the install to occur for the admin account. It doesn't get installed for the user I'm currently logged in as, or any other user - it only gets installed for the admin user.

This make a stange sort of sense as I understand that the default SetShellVarContext setting is "current" (for the current user, but I guess the "RequestExecutionLevel admin" is causing the install to run as the admin user.

But I can't imagine this situation being much use - a user will expect it to be installed either for the currently logged in user OR for all users.

I then tried removing the "RequestExecutionLevel admin", and added a "SetShellVarContext all" to the install and uninstall sections. I also added a MessageBox statement to see what the pathnames were being expanded to. This seemed to successfully install for all users with the ALL USERS program menu and desktop pathnames being used ...... BUT the desktop path appeared as

C:\Users\Public\Desktop

but this folder does not seem to exist even when viewing hidden files! There is a

C:\Users\Public\Public Desktop

and if you type C:\Users\Public\Desktop into Widows explorer it ends up listing C:\Users\Public\Public Desktop. It's as if there is a link from one to the other, but I can't actually see the link.

Shouldn't NSIS use the "Public Desktop" path as this is the one that is visible?

Anyway, to summarise, "SetShellVarContext all" seems to give an all-users installation and uninstallation OK. But the "RequestExecutionLevel admin" seems to be no use as it will only install into the admin user account. So it seems there is no way of installing into the CURRENT user only.


If you want to put shortcuts in the current users start menu, you must use "RequestExecutionLevel user" (This means you can NOT write to $programfiles or HKEY_LOCAL_MACHINE)

IMHO, you have two kinds of installers:

Current user (ONLY!):
-RequestExecutionLevel user
-SetShellVarContext current
-Install in $LOCALAPPDATA
-Uninstall reg info in HKCU

All users:
-RequestExecutionLevel admin
-SetShellVarContext all
-Install in $programfiles
-Uninstall reg info in HKLM

Most installers assume the user is admin and create a mixed type installer, Vista changed this with UAC (These problems have always been here, just most people run as admin on older NT systems)


You also might wanna look into the UAC plugin


As far as the Public Desktop path goes, NSIS uses the actual path on the file system provided by SHGetSpecialFolderLocation(and friends), explorer is playing games with shell exstensions/desktop.ini's/symlinks to make it "look good"