How to open folder as admin? (Linux)

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

How to open folder as admin? (Linux)

Post by AZJIO »

Code: Select all

EnableExplicit

#q$    = Chr(34) ; "
#q1$   = Chr(39) ; '
Define Path$ = "/usr/share/nemo"
Define fm$    = "nemo"
; RunProgram(fm$, #q$ + Path$ + #q$, "")
RunProgram("bash", "-c" + #q$ + "pkexec " + fm$ + " " + #q1$ + Path$ + #q1$ + " &" + #q$, "")
RunProgram("pkexec", fm$ + " " + #q1$ + Path$ + #q1$, "")
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to open folder as admin? (Linux)

Post by infratec »

Why not:

Code: Select all

RunProgram("/bin/pkexec", "/usr/share/nemo/nemo", "", #PB_Program_Wait)
I don't know if the paths are correct.

Or do you want to open a shell in a speific folder as root user?

Code: Select all

RunProgram("/bin/pkexec", "/bin/bash -c 'cd /usr/share/nemo; exec " + #DQUOTE$ + "${SHELL}" + #DQUOTE$ + "'", "", #PB_Program_Wait)
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: How to open folder as admin? (Linux)

Post by AZJIO »

Code: Select all

RunProgram("pkexec", "nemo " + #DQUOTE$ +"/usr/share/nemo" + #DQUOTE$, "", #PB_Program_Wait)
The #PB_Program_Wait flag turned out to be decisive.
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: How to open folder as admin? (Linux)

Post by AZJIO »

But now you need to close the folder to select another directory. I use this in the SaveFolders program. Now the "@" symbol at the beginning of the path indicates that the folder must be opened with root privileges. Most system folders without root rights do not make sense to open, since it is not possible to copy or edit anything. Basically, this need arises when setting up the OS, immediately after installation. In the end, you just need to know that you need to close the directory opened as root before opening the next one. I have added the directories where changes need to be made. For example, I add fonts, themes, icons, backgrounds, etc.
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: How to open folder as admin? (Linux)

Post by AZJIO »

With the help of the thread it was possible not to block the program.

Code: Select all

tmp$ = "-c " + #DQUOTE$ + "pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY " + fm$ + " '" + Path$ + "'" + #DQUOTE$
CreateThread(@Thread(), @tmp$)

Procedure Thread(*Param)
	RunProgram("bash", PeekS(*Param), "", #PB_Program_Wait)
EndProcedure
Post Reply