Sudo relauncher class (using pkexec)
Posted
#1
(In Topic #445)
Banned
I've been writing a class based on something my pkAppMan application does…
As it loads it checks the pkexec policy list to see if '/usr/bin/gbr3' is in it.
if not run as root and gbr3 is not in pkexec list then it displays a message
telling the user to run the application from a shell as root to configure pkexec
to allow gambas apps to ask for root.
Running as root from a terminal will auto-add gbr3 to pkexec list if it's not there and
inform the user via a terminal message that it's been added and now pkexec will work for gambas apps.
now the app can be launched in many ways and still ask for root access via pkexec. (even just double clicking the application.gambas file.)
if gbr3 exists in pkexec list and app has not been run as root it uses the shell command to relaunch itself and quit the current loading app
With the following code…
Code
' Gambas class file
Public pkp As PkPolicy
Public Sub Form_Open()
pkp = New PkPolicy
pkp.pkLaunch
End
ToDo….
Make it pass any other additional arguments from the initial calling command
Posted
Banned
It will now pass any additional given arguments to the app being launched.
I've renamed it to PkLaunch.class as it wasn't the pkPolicy.class that's another class i wrote for pkAppMan that fully manages the pkexec policy file. but i used that class and cut it down to the relauncher , forgot to rename it.
Have made it translatable.
So .. add the class to your project.
add this code to the begining of your Form_Open() Event..
Code
Dim myPk as PkLaunch
myPk = New PkLaunch
myPk.LaunchAnd you have a root enabled app
1 guest and 0 members have just viewed this.





