Bug 1333789 - Try to avoid UAC prompts during automated installations using INI files. r=agashlin draft
authorMatt Howell <mhowell@mozilla.com>
Tue, 07 Feb 2017 11:00:10 -0800
changeset 480045 e5d87963636350fa4b7b671dbaa9c1760a6d26c2
parent 479958 e677ba018b22558fef1d07b74d416fd3a28a5dc3
child 544855 363f28e04316436f2f627d066e3e96266d4d19af
push id44436
push usermhowell@mozilla.com
push dateTue, 07 Feb 2017 19:02:11 +0000
reviewersagashlin
bugs1333789
milestone54.0a1
Bug 1333789 - Try to avoid UAC prompts during automated installations using INI files. r=agashlin MozReview-Commit-ID: CIOKXTT5AHh
toolkit/mozapps/installer/windows/nsis/common.nsh
--- a/toolkit/mozapps/installer/windows/nsis/common.nsh
+++ b/toolkit/mozapps/installer/windows/nsis/common.nsh
@@ -4951,19 +4951,16 @@
       ${EndUnless}
 
       !ifdef HAVE_64BIT_BUILD
         SetRegView 64
       !endif
 
       ${GetParameters} $R8
 
-      ; Require elevation if the user can elevate
-      ${ElevateUAC}
-
       ${If} $R8 != ""
         ; Default install type
         StrCpy $InstallType ${INSTALLTYPE_BASIC}
 
         ${Unless} ${Silent}
           ; Manually check for /S in the command line due to Bug 506867
           ClearErrors
           ${GetOptions} "$R8" "/S" $R7
@@ -5006,24 +5003,38 @@
             ClearErrors
             ${If} ${FileExists} "$INSTDIR"
               GetTempFileName $R6 "$INSTDIR"
               FileOpen $R5 "$R6" w
               FileWrite $R5 "Write Access Test"
               FileClose $R5
               Delete $R6
               ${If} ${Errors}
-                ; Nothing initialized so no need to call OnEndCommon
-                Quit
+                ; Attempt to elevate and then try again.
+                ${ElevateUAC}
+                GetTempFileName $R6 "$INSTDIR"
+                FileOpen $R5 "$R6" w
+                FileWrite $R5 "Write Access Test"
+                FileClose $R5
+                Delete $R6
+                ${If} ${Errors}
+                  ; Nothing initialized so no need to call OnEndCommon
+                  Quit
+                ${EndIf}
               ${EndIf}
             ${Else}
               CreateDirectory "$INSTDIR"
               ${If} ${Errors}
-                ; Nothing initialized so no need to call OnEndCommon
-                Quit
+                ; Attempt to elevate and then try again.
+                ${ElevateUAC}
+                CreateDirectory "$INSTDIR"
+                ${If} ${Errors}
+                  ; Nothing initialized so no need to call OnEndCommon
+                  Quit
+                ${EndIf}
               ${EndIf}
             ${EndIf}
 
             ReadINIStr $R8 $R7 "Install" "QuickLaunchShortcut"
             ${If} $R8 == "false"
               StrCpy $AddQuickLaunchSC "0"
             ${Else}
               StrCpy $AddQuickLaunchSC "1"
@@ -5057,16 +5068,22 @@
 
             !ifndef NO_STARTMENU_DIR
               ReadINIStr $R8 $R7 "Install" "StartMenuDirectoryName"
               ${If} $R8 != ""
                 StrCpy $StartMenuDir "$R8"
               ${EndIf}
             !endif
           ${EndIf}
+        ${Else}
+          ; If this isn't an INI install, we need to try to elevate now.
+          ; We'll check the user's permission level later on to determine the
+          ; default install path (which will be the real install path for /S).
+          ; If an INI file is used, we try to elevate down that path when needed.
+          ${ElevateUAC}
         ${EndUnless}
       ${EndIf}
       ClearErrors
 
       Pop $R5
       Pop $R6
       Pop $R7
       Pop $R8