Shortcuts removal fails on Windows Vista: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Made examples more correct (and complicated))
(local link)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Windows Vista automatically identifies installer executables, including NSIS installers, and asks the user permission to run them with elevated privileges. Automatic detection, however, comes with  the price of automatic backward compatibility tricks. One of which is automatic relocation of shortcuts created in the Start Menu to All Users' Start Menu.
Windows Vista and Windows 7 automatically identify installer executables, including NSIS installers, and ask the user permission to run them with elevated privileges. Automatic detection, however, comes with  the price of automatic backward compatibility tricks. One of which is automatic relocation of shortcuts created in the Start Menu to the All Users' Start Menu.


To workaround this, use the new RequestExecutionLevel command or create the shortcuts in All Users' folders in the first place, using SetShellVarContext.
To workaround this, use the new [[Reference/RequestExecutionLevel|RequestExecutionLevel]] command or create the shortcuts in All Users' folders in the first place, using [[Reference/SetShellVarContext|SetShellVarContext]].


<highlight-nsis>OutFile vista.exe
<highlight-nsis>OutFile vista.exe
Line 9: Line 9:


Section
Section
   CreateShortcut "$SMPROGRAMS\Vista Test\hello.lnk" $WINDIR\notepad.exe
  CreateDirectory "$SMPROGRAMS\Vista Test"
   CreateShortcut "$SMPROGRAMS\Vista Test\hello.lnk" $WINDIR\notepad.exe
   WriteUninstaller $EXEDIR\uninst.exe
   WriteUninstaller $EXEDIR\uninst.exe
SectionEnd
SectionEnd
Line 20: Line 21:
<highlight-nsis>OutFile vista.exe
<highlight-nsis>OutFile vista.exe
Name Vista
Name Vista
RequestExecutionLevel admin #NOTE: You still need to check user rights with UserInfo!


Function .onInit
Function .onInit
Line 27: Line 30:
Section
Section
   SetShellVarContext all
   SetShellVarContext all
   CreateShortcut "$SMPROGRAMS\Vista Test\hello.lnk" $WINDIR\notepad.exe
  CreateDirectory "$SMPROGRAMS\Vista Test"
   CreateShortcut "$SMPROGRAMS\Vista Test\hello.lnk" $WINDIR\notepad.exe
   WriteUninstaller $EXEDIR\uninst.exe
   WriteUninstaller $EXEDIR\uninst.exe
SectionEnd
SectionEnd

Latest revision as of 05:39, 26 August 2013

Windows Vista and Windows 7 automatically identify installer executables, including NSIS installers, and ask the user permission to run them with elevated privileges. Automatic detection, however, comes with the price of automatic backward compatibility tricks. One of which is automatic relocation of shortcuts created in the Start Menu to the All Users' Start Menu.

To workaround this, use the new RequestExecutionLevel command or create the shortcuts in All Users' folders in the first place, using SetShellVarContext.

OutFile vista.exe
Name Vista
 
RequestExecutionLevel user
 
Section
  CreateDirectory "$SMPROGRAMS\Vista Test"
  CreateShortcut  "$SMPROGRAMS\Vista Test\hello.lnk" $WINDIR\notepad.exe
  WriteUninstaller $EXEDIR\uninst.exe
SectionEnd
 
Section uninstall
  Delete "$SMPROGRAMS\Vista Test\hello.lnk"
  RMDir "$SMPROGRAMS\Vista Test"
SectionEnd
OutFile vista.exe
Name Vista
 
RequestExecutionLevel admin #NOTE: You still need to check user rights with UserInfo!
 
Function .onInit
#TODO: call UserInfo plugin to make sure user is admin
FunctionEnd
 
Section
  SetShellVarContext all
  CreateDirectory "$SMPROGRAMS\Vista Test"
  CreateShortcut  "$SMPROGRAMS\Vista Test\hello.lnk" $WINDIR\notepad.exe
  WriteUninstaller $EXEDIR\uninst.exe
SectionEnd
 
Section uninstall
  SetShellVarContext all
  Delete "$SMPROGRAMS\Vista Test\hello.lnk"
  RMDir "$SMPROGRAMS\Vista Test"
SectionEnd