Forum > Linux

[Solved]Is it possible for a console program, to detect if being run as 'su'?!?

(1/2) > >>

cdbc:
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:
Maybe here?
https://serverfault.com/questions/568627/can-a-program-tell-it-is-being-run-under-sudo

cdbc:
Hi
Thanks @Zvoni  8)
...and the answer is:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses ..., baseunix;  ...  IsRoot:= (FpGetuid = 0);   ... Regards Benny

myisjwj:
https://www.cnblogs.com/jwjss/p/17914594.html

Thaddy:
Windows is a bit more cumbersome:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$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.

Navigation

[0] Message Index

[#] Next page

Go to full version