CrushBug
3rd September 2009 00:08 UTC
CreateShortCut vs. Vista SP1 and SP2
I wanted to post this in case it might help someone else. I was having a problem creating shortcuts under Vista SP1 and NSIS 2.45. I was going crazy and when we changed to a Vista SP2 box, the exact same code worked. Here is the code snippet
SetOutPath "$INSTDIR"
>SetShellVarContext all
>${LogWrite} 'creating shortcut "$SMPROGRAMS\$StartMenuLocation\${SAFE_PRODUCT_NAME}.lnk" "$ProgramLocation${PRODUCT_MAINEXE}"'
>ClearErrors
CreateShortCut "$SMPROGRAMS\$StartMenuLocation\${SAFE_PRODUCT_NAME}.lnk" "$ProgramLocation${PRODUCT_MAINEXE}"
>${If} ${Errors}
${
LogWrite} " - error creating shortcut"
>${EndIf}
That code under SP1 gives and error, under SP2, it works.
The exploded paths from the log are:
Doesn't work:
[Wednesday Sep 02 15:09:00 2009] creating shortcut "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Creator\Creator.lnk" "C:\Program Files\Creator\Creator.exe"
[Wednesday Sep 02 15:09:00 2009] - error creating shortcut
Works:
[Wednesday Sep 02 15:48:45 2009] creating shortcut "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Creator\Creator.lnk" "C:\Program Files\Creator\Creator.exe"
Does anyone know anything more about this wierdness?
In the end, I kind of need to support Vista SP1 so I am still looking for a workaround.
Anders
3rd September 2009 00:29 UTC
First off, you are running as admin right? (RequestExecutionLevel admin)
Also, the folder "Creator" ($StartMenuLocation) needs to exist before you create the shortcut.
You could also monitor the installer with Process Monitor from MS/Sysinternals and see if/why a file operation fails
CrushBug
3rd September 2009 00:50 UTC
Originally posted by Anders
First off, you are running as admin right? (RequestExecutionLevel admin)
Correct.
Also, the folder "Creator" ($StartMenuLocation) needs to exist before you create the shortcut.
Correct the folder in this case was successfully created in the code line right before this.
You could also monitor the installer with Process Monitor from MS/Sysinternals and see if/why a file operation fails
Yeah, I will try and poke around more and see if I can narrow it down.
It's really weird.
edit: folder creation clarity
pengyou
3rd September 2009 14:40 UTC
I think the CreateShortCut command fails if the shortcut already exists and it is marked Read-Only so I always change the attributes before updating the shortcut.
CrushBug
3rd September 2009 16:26 UTC
Originally posted by pengyou
I think the CreateShortCut command fails if the shortcut already exists and it is marked Read-Only so I always change the attributes before updating the shortcut.
I wish, but we are not talking about existing shortcuts nor anything to do with read-only.
Both are QA test systems with no traces of the program on them before installation. The
only discernible difference between the two systems is SP1 and SP2. Tragically, we don't have any more SP1 systems around to verify this on, but it is 100% reproducible on the systems we have.
CrushBug
3rd September 2009 18:27 UTC
Added comedy value:
We just updated the QA box from SP1 to SP2 and the shortcuts work. Same computer and software, just an SP change.