]> git.sesse.net Git - vlc/blobdiff - extras/package/win32/vlc.win32.nsi.in
Win32: don't launch VLC as admin after installing
[vlc] / extras / package / win32 / vlc.win32.nsi.in
index f7712f9fa541a3351e536c1b02bb9c80d51cac74..8c462a008e8e96f22ee2bb814a62e739982d57b7 100644 (file)
@@ -48,6 +48,11 @@ InstType $Name_InstTypeRecommended
 InstType $Name_InstTypeMinimum
 InstType $Name_InstTypeFull
 
+RequestExecutionLevel user
+!addincludedir .
+!addplugindir .
+!include UAC.nsh
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; NSIS Modern User Interface configuration ;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -75,7 +80,17 @@ InstType $Name_InstTypeFull
   ; Instfiles page
     !insertmacro MUI_PAGE_INSTFILES
   ; Finish page
-    !define MUI_FINISHPAGE_RUN "$INSTDIR\vlc.exe"
+
+    Function ExecAppFile
+      Exec '$INSTDIR\vlc.exe'
+    FunctionEnd
+
+    Function AppRunAs
+      !insertmacro UAC.CallFunctionAsUser ExecAppFile
+    FunctionEnd
+
+    !define MUI_FINISHPAGE_RUN
+    !define MUI_FINISHPAGE_RUN_FUNCTION AppRunAs
     !define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\README.txt"
     !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
     !define MUI_FINISHPAGE_LINK $Link_VisitWebsite
@@ -314,11 +329,15 @@ FunctionEnd
 ; 3. Delete prefs and cache ;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+Function ExecCacheGen
+  ExecWait "$INSTDIR\vlc-cache-gen.exe $APPDATA\\VideoLAN\\VLC"
+FunctionEnd
+
 !macro gencache
   SetShellVarContext all
   CreateDirectory "$APPDATA\\VideoLAN"
   CreateDirectory "$APPDATA\\VideoLAN\\VLC"
-  ExecWait "$INSTDIR\vlc-cache-gen.exe $APPDATA\\VideoLAN\\VLC"
+  !insertmacro UAC.CallFunctionAsUser ExecCacheGen
   SetShellVarContext current
 !macroend
 
@@ -664,6 +683,27 @@ SectionEnd
 
 ;;; Start function
 Function .onInit
+
+UAC_Elevate:
+    UAC::RunElevated
+    StrCmp 1223 $0 UAC_ElevationAborted
+    StrCmp 0 $0 0 UAC_Err
+    StrCmp 1 $1 0 UAC_Success
+    Quit
+
+UAC_Err:
+    MessageBox mb_iconstop "Unable to elevate, error $0"
+    Abort
+
+UAC_ElevationAborted:
+    MessageBox mb_iconstop "This installer requires admin access, aborting!"
+    Abort
+
+UAC_Success:
+    StrCmp 1 $3 +4
+    StrCmp 3 $1 0 UAC_ElevationAborted
+    MessageBox mb_iconstop "This installer requires admin access, try again"
+    goto UAC_Elevate
   !insertmacro MUI_LANGDLL_DISPLAY
 
   !include "languages\english.nsh"
@@ -734,6 +774,13 @@ Function .onInit
 
 FunctionEnd
 
+Function .OnInstFailed
+    UAC::Unload
+FunctionEnd
+
+Function .OnInstSuccess
+    UAC::Unload
+FunctionEnd
 ;; End function
 Section -Post
   WriteUninstaller "$INSTDIR\uninstall.exe"
@@ -916,13 +963,38 @@ SectionEnd
   !insertmacro MUI_DESCRIPTION_TEXT ${SEC92} $Desc_Section92
 !insertmacro MUI_UNFUNCTION_DESCRIPTION_END
 
-;Function un.onUninstSuccess
-;  HideWindow
-;  MessageBox MB_ICONINFORMATION|MB_OK \
-;    "$(^Name) was successfully removed from your computer."
-;FunctionEnd
+Function un.OnUnInstFailed
+    UAC::Unload
+FunctionEnd
+
+Function un.OnUnInstSuccess
+    UAC::Unload
+    Delete "$INSTDIR\UAC.dll"
+FunctionEnd
 
 Function un.onInit
+
+UAC_Elevate:
+    UAC::RunElevated
+    StrCmp 1223 $0 UAC_ElevationAborted
+    StrCmp 0 $0 0 UAC_Err
+    StrCmp 1 $1 0 UAC_Success
+    Quit
+
+UAC_Err:
+    MessageBox mb_iconstop "Unable to elevate, error $0"
+    Abort
+
+UAC_ElevationAborted:
+    MessageBox mb_iconstop "This installer requires admin access, aborting!"
+    Abort
+
+UAC_Success:
+    StrCmp 1 $3 +4
+    StrCmp 3 $1 0 UAC_ElevationAborted
+    MessageBox mb_iconstop "This installer requires admin access, try again"
+    goto UAC_Elevate
+
   !insertmacro MUI_UNGETLANGUAGE
 
   !include "languages\english.nsh"