Archive: CreateShortCut Vista Issue

CreateShortCut Vista Issue
I apologize if this has been answered before. I searched the forum, but didn't find anything exactly like this.

My 'Modern UI' EXE install runs fine on XP. On Vista it runs fine except that it does not create the desktop shortcut unless I right-click the EXE and 'Run as Administrator'. (I am logged in as a user with Admin priviledges.) I thought maybe I needed the NSIS UAC plugin so the script could create the shortcut as Administrator, but after downloading and reading everything, sounds like the user running the install needs the desktop shortcut, not the Administrator, which is the way it is already configured. The user I am logged in as when I run the install can manually create desktop shortcuts without a problem. The script has the code to request user application privileges:

;Request application privileges for Windows Vista
RequestExecutionLevel user

So I'm confused. Any help would be appreciated. Haven't tried it on Windows 7, but am guessing the same issue would occur. This is NSIS version 2.46.


Did you call "SetShellVarContext all"? If not, CreateShortcut on $desktop should work with "RequestExecutionLevel user" unless the desktop directory is otherwise locked down.

Yes, this is the standard 'Modern UI' example script and it has:

SetShellVarContext all

Should that be removed in this case?

Well, yes, "SetShellVarContext all" turns $desktop into c:\programdata\... or whatever (all users folder on < Vista, and you need to be admin to write there)

Sorry to be so dense, but are you saying SetShellVarContext functions differently between XP and Vista? Just to clarify, here's the section that creates the desktop shortcut in XP. So if I remove the SetShellVarContext, it should work in both XP and Vista because $DESKTOP doesn't get changed? Just confused about why it works in XP if $DESKTOP is changed by SetShellVarContext. Thanks.

Section "myApp v0.45" SecInst
SetShellVarContext all
CreateDirectory "\myApp"
SetOutPath "$INSTDIR"
;Store installation folder
WriteRegStr HKCU "Software\myApp" "" $INSTDIR
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
; create the desktop shortcut
CreateShortCut "$DESKTOP\myApp.lnk" "$INSTDIR\myApp.jar" "" "$INSTDIR\myApp.ico"

Don't use SetShellVarContext all. Also why do you have CreateDirectory "\myApp"? You should never use relative paths.


Originally posted by HondaGuy
Sorry to be so dense, but are you saying SetShellVarContext functions differently between XP and Vista?
No it works exactly the same, you just failed to test on XP as non admin

Actually, the test I did on XP was done the same way as the test I did on Vista. As a standard user, but with 'Computer Administrator' privileges. That's why I was confused about the inconsistent results. I'll remove 'SetShellVarContext all' and start another round of testing. (Thought I started with one of the Modern UI examples, but none of them use that command, so not sure where I got the code that has it. Has been a while since I built the script and it has been working for everyone doing XP installs.)


"As a standard user, but with 'Computer Administrator' privileges" what does that even mean? A standard (aka limited, normal) user is not a member of the administrators group.

Start/Control Panel/User Accounts

Looking at the user which is logged on and running the install script:

Computer Administrator
Password Protected

This is XP. I'll have to check the Vista machine which had the issue (can't get to it until Monday), but I purposely set it up the same way, so I would expect similar attributes for the user. Administrator privileges means that it is a user other than 'Administrator' which has been given the 'Computer administrator' type instead of 'Limited' type. (Those are the only 2 options at account setup.)