mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-28 10:02:14 +00:00
ADD: Check administrator privileges first
This commit is contained in:
parent
0df001f7cf
commit
70c3f3b5dd
3 changed files with 14 additions and 8 deletions
|
|
@ -218,11 +218,6 @@ function GetCurrentUserName : String;
|
|||
}
|
||||
function GetComputerNetName: String;
|
||||
|
||||
var
|
||||
// While elevated operations is not implemented
|
||||
// https://doublecmd.sourceforge.io/mantisbt/view.php?id=110
|
||||
AdministratorPrivileges: Boolean = True;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
|
|
|
|||
|
|
@ -851,7 +851,7 @@ begin
|
|||
if Result then
|
||||
begin
|
||||
case ElevationType of
|
||||
TokenElevationTypeDefault: Result:= False; // The token does not have a linked token. (UAC disabled)
|
||||
TokenElevationTypeDefault: Result:= True; // The token does not have a linked token. (UAC disabled)
|
||||
TokenElevationTypeFull: Result:= True; // The token is an elevated token. (Administrator)
|
||||
TokenElevationTypeLimited: Result:= False; // The token is a limited token. (User)
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ implementation
|
|||
uses
|
||||
SysUtils
|
||||
{$IF DEFINED(MSWINDOWS)}
|
||||
, Windows, DCOSUtils, ShellApi
|
||||
, Windows, DCOSUtils, ShellApi, uMyWindows
|
||||
{$ELSEIF DEFINED(UNIX)}
|
||||
, Unix, BaseUnix, DCUnix
|
||||
{$IF DEFINED(DARWIN)}
|
||||
|
|
@ -23,6 +23,9 @@ uses
|
|||
{$ENDIF}
|
||||
;
|
||||
|
||||
var
|
||||
AdministratorPrivileges: Boolean;
|
||||
|
||||
procedure WaitProcess(Process: UIntPtr);
|
||||
{$IF DEFINED(MSWINDOWS)}
|
||||
begin
|
||||
|
|
@ -40,12 +43,13 @@ end;
|
|||
function ElevationRequired(LastError: Integer = 0): Boolean;
|
||||
{$IF DEFINED(MSWINDOWS)}
|
||||
begin
|
||||
if (Win32MajorVersion < 6) then Exit(False);
|
||||
if AdministratorPrivileges then Exit(False);
|
||||
if LastError = 0 then LastError:= GetLastError;
|
||||
Result:= (LastError = ERROR_ACCESS_DENIED) or (LastError = ERROR_PRIVILEGE_NOT_HELD) or (LastError = ERROR_INVALID_OWNER);
|
||||
end;
|
||||
{$ELSE}
|
||||
begin
|
||||
if AdministratorPrivileges then Exit(False);
|
||||
if LastError = 0 then LastError:= GetLastOSError;
|
||||
Result:= (LastError = ESysEPERM) or (LastError = ESysEACCES);
|
||||
end;
|
||||
|
|
@ -170,5 +174,12 @@ begin
|
|||
end;
|
||||
{$ENDIF}
|
||||
|
||||
initialization
|
||||
{$IF DEFINED(UNIX)}
|
||||
AdministratorPrivileges:= (fpGetUID = 0);
|
||||
{$ELSE}
|
||||
AdministratorPrivileges:= (Win32MajorVersion < 6) or IsUserAdmin;
|
||||
{$ENDIF}
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue