Browse Source

Bug 1491: Installation fails when started by a non-privileged user on a system, where elevating to administrator privileges is disabled

https://winscp.net/tracker/1491
(cherry picked from commit cbc02d7fa2f9975ac356458bc72f2a87857fb337)

Source commit: 5a971ec7f8fb188e911eb146024584c6a4d18670
Martin Prikryl 9 years ago
parent
commit
1e75b99b9b
1 changed files with 36 additions and 28 deletions
  1. 36 28
      deployment/winscpsetup.iss

+ 36 - 28
deployment/winscpsetup.iss

@@ -894,39 +894,47 @@ var
   Params: string;
   S: string;
 begin
-  // Collect current instance parameters
-  for I := 1 to ParamCount do
+  Result := not CmdLineParamExists('/Elevated');
+  if not Result then
   begin
-    S := ParamStr(I);
-    // Unique log file name for the elevated instance
-    if CompareText(Copy(S, 1, 5), '/LOG=') = 0 then
-    begin
-      S := S + '-elevated';
-    end;
-    // Do not pass our /SL5 switch
-    if CompareText(Copy(S, 1, 5), '/SL5=') <> 0 then
+    Log('Elevation already attempted and silently failed, continuing unelevated');
+  end
+    else
+  begin
+    // Collect current instance parameters
+    for I := 1 to ParamCount do
     begin
-      Params := Params + AddQuotes(S) + ' ';
+      S := ParamStr(I);
+      // Unique log file name for the elevated instance
+      if CompareText(Copy(S, 1, 5), '/LOG=') = 0 then
+      begin
+        S := S + '-elevated';
+      end;
+      // Do not pass our /SL5 switch
+      if CompareText(Copy(S, 1, 5), '/SL5=') <> 0 then
+      begin
+        Params := Params + AddQuotes(S) + ' ';
+      end;
     end;
-  end;
 
-  // ... and add selected language
-  Params := Params + '/LANG=' + ActiveLanguage;
+    // ... and add selected language
+    Params := Params + '/LANG=' + ActiveLanguage + ' /Elevated';
 
-  Log(Format('Elevating setup with parameters [%s]', [Params]));
-  RetVal := ShellExecute(0, 'runas', ExpandConstant('{srcexe}'), Params, '', SW_SHOW);
-  Log(Format('Running elevated setup returned [%d]', [RetVal]));
-  Result := (RetVal > 32);
-  // if elevated executing of this setup succeeded, then...
-  if Result then
-  begin
-    Log('Elevation succeeded');
-    // exit this non-elevated setup instance
-    ExitProcess(0);
-  end
-    else
-  begin
-    Log(Format('Elevation failed [%s]', [SysErrorMessage(RetVal)]));
+    Log(Format('Elevating setup with parameters [%s]', [Params]));
+    RetVal := ShellExecute(0, 'runas', ExpandConstant('{srcexe}'), Params, '', SW_SHOW);
+    Log(Format('Running elevated setup returned [%d]', [RetVal]));
+    Result := (RetVal > 32);
+    // if elevated executing of this setup succeeded, then...
+    if Result then
+    begin
+      Log('Elevation succeeded');
+      // exit this non-elevated setup instance
+      ExitProcess(0);
+    end
+      else
+    begin
+      Log(Format('Elevation failed [%s]', [SysErrorMessage(RetVal)]));
+    end;
   end;
 end;