Skip to content

Commit

Permalink
Bug 1491: Installation fails when started by a non-privileged user on…
Browse files Browse the repository at this point in the history
… a system, where elevating to administrator privileges is disabled

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

Source commit: 5a971ec7f8fb188e911eb146024584c6a4d18670
  • Loading branch information
martinprikryl committed Jan 28, 2018
1 parent cda1160 commit 1e75b99
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions deployment/winscpsetup.iss
Expand Up @@ -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;
Expand Down

0 comments on commit 1e75b99

Please sign in to comment.