Is User a member of administrators group

Linux specific forum
danielheth
New User
New User
Posts: 9
Joined: Mon Dec 01, 2014 5:12 pm
Location: Arkansas
Contact:

Is User a member of administrators group

Post by danielheth »

is there a way to tell if the user running my program is an administrator or not? On windows i simply call IsUserAdmin_(), but looking for the linux equivalent...
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Is User a member of administrators group

Post by idle »

Not sure but you could try to write a file to a directory that requires root access

Code: Select all

Procedure IsUserAdmin_()
  Protected rand.l,file.s 
  rand = Random($FFFFFF)
  file.s = MD5Fingerprint(@rand,4) 
  
  If CreateFile(0,"/etc/"+file) 
    CloseFile(0) 
    DeleteFile("/etc/"+file)
    ProcedureReturn 1 
  EndIf 
EndProcedure 

Debug IsUserAdmin_()
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Is User a member of administrators group

Post by Vera »

Hi,
this might be what you're looking for:

Code: Select all

Debug "group-id of current user: " +Str(getgid_())
Source: Shows group-id of current user
Please see Oma's http://www.chabba.de/LinuxAPI.html /Misc for more


@idle ~ I like solutions like yours :-)

greets ~ Vera
User avatar
Shardik
Addict
Addict
Posts: 2067
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Is User a member of administrators group

Post by Shardik »

danielheth wrote:On windows i simply call IsUserAdmin_(), but looking for the linux equivalent...
The equivalent in Linux is getuid_() or geteuid_():
http://www.purebasic.fr/english/viewtop ... 64&start=1
http://www.purebasic.fr/german/viewtopi ... 39&start=3
Post Reply