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

Ask about the individual Gambas components here.
Post Reply
User avatar
Posts: 652
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..

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..

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

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

(24.22 KiB) Downloaded 10 times
Last edited by BruceSteers on Friday 27th August 2021 7:43pm, edited 1 time in total.
Wishing well

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

Post Reply