NoRoot.class (get User and default paths info when root)

Ask about the individual Gambas components here.
Post Reply
User avatar
BruceSteers
Posts: 657
Joined: Thursday 23rd July 2020 5:20pm

NoRoot.class (get User and default paths info when root)

Post by BruceSteers » Friday 27th August 2021 5:36pm

Here is a class you may be able to use..
NoRoot.class

What it does...
I gets info like UserName / UserHome / Desktop.Path but unlike User.Home/User.Name etc it will not give "root" username if app is run as superuser.

It is basically commands ripped from gb.desktop and gb.gui.base/Desktop.class and modified to get normal user details

It has the following Properties/Methods..

Properties..
NoRoot.UserName ' same as User.Name but not "root"
NoRoot.UserHome ' same as User.Home but not "root"
NoRoot.Environment (Collection) ' if root it will contain normal user environment variables.
NoRoot.DesktopPath ' same as Desktop.Path but not root

Methods...
NoRoot.GetDirectory(Type As String = "Desktop") ' gets directory paths for Desktop / Music / etc but user paths not root

How it works...
If not run as root it returns the same as Desktop.class and System.User

If su -c or sudo is used it uses algorithms to get the users data not roots data

Source...
Attachments
NoRootUser-0.0.1.zip
(24.22 KiB) Downloaded 34 times
Last edited by BruceSteers on Friday 27th August 2021 7:43pm, edited 1 time in total.
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
BruceSteers
Posts: 657
Joined: Thursday 23rd July 2020 5:20pm

Re: NoRoot.class (get User and default paths info when root)

Post by BruceSteers » Sunday 19th September 2021 9:12am

Slight update folks...

modified because using pkexec did not work

now it works with sudo, su and pkexec.

Added a ReadMe

No docs needed i think
Attachments
NoRootUser-1.1.1.tar.gz
(14.78 KiB) Downloaded 48 times
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
BruceSteers
Posts: 657
Joined: Thursday 23rd July 2020 5:20pm

Re: NoRoot.class (get User and default paths info when root)

Post by BruceSteers » Sunday 19th September 2021 6:26pm

PS i changed the class name to NotRoot.class
Wishing well
Bruce

If at first you don't succeed , try it differently.

Post Reply