[Solved]Is it possible for a console program, to detect if being run as 'su'?!? lazarus / 32-Linux ---------------------------------------------------------------------- cdbc · 2024-08-21 11:24 Hi Is there any way, a console program can detect if it's being run as 'superuser'? If so, how? This question is mainly about Linux, but could be interesting to about winders too... Regards Benny ---------------------------------------------------------------------- Zvoni · 2024-08-21 11:28 Maybe here? https://serverfault.com/questions/568627/can-a-program-tell-it-is- being-run-under-sudo ---------------------------------------------------------------------- cdbc · 2024-08-21 11:50 Hi Thanks @Zvoni  ...and the answer is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ..., baseunix;  ...  IsRoot:= (FpGetuid = 0);   ... Regards Benny ---------------------------------------------------------------------- myisjwj · 2024-09-14 01:26 https://www.cnblogs.com/jwjss/p/17914594.html ---------------------------------------------------------------------- Thaddy · 2024-09-14 04:53 Windows is a bit more cumbersome:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}uses windows; function IsRunningAsAdmin: Boolean;var  hToken: THandle = 0;  pElevation: TOKEN_ELEVATION;  dwSize: DWORD = SizeOf(TOKEN_ELEVATION);begin  Result := False;  if OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, hToken) then    if GetTokenInformation(hToken, TokenElevation, @pElevation, dwSize, dwSize) then    begin        Result := pElevation.TokenIsElevated <> 0;      CloseHandle(hToken);    end;end;begin  writeln(isrunningasadmin);end. ---------------------------------------------------------------------- marcov · 2024-09-14 09:05 Quote from: Thaddy on September 14, 2024, 06:53:44 amWindows is a bit more cumbersome:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [/quote] No it is not. [code=pascal]uses winutils; begin  result:=IsWindowsAdmin();end; ---------------------------------------------------------------------- Thaddy · 2024-09-14 09:32 Maybe, but my code is much more concise than the convoluted code in winutils. Has also less dependencies. It is also a straight port from C on msdn. ---------------------------------------------------------------------- Kays · 2024-09-14 09:38 You should not “detect” whether your console program is su’d, but simply access the resources that require elevated privileges. Specifically Linux has capabilities(7) that allow non‑root users to perform certain administrative tasks, so testing for a zero UID may give false negatives. Or it just may happen that the file permissions mode is very liberal, so being root isn’t required at all.