Page 1 of 1
Linux Reboot/Shutdown using PB app
Posted: Thu Oct 14, 2021 7:21 pm
by swhite
Hi
I would like to be able to have my Purebasic application reboot or shutdown a Linux PC. A number of the commands to accomplish this require root privileges. However RunProgram does not have the ability to specify a user and password. Does anyone have a suggestion about how this might be accomplished? I am running on OpenSuse 15.3 and PB 5.73.
Thanks,
Simon
Re: Linux Reboot/Shutdown using PB app
Posted: Thu Oct 14, 2021 9:19 pm
by mk-soft
Re: Linux Reboot/Shutdown using PB app
Posted: Fri Oct 15, 2021 11:13 am
by infratec
You can also use sudo with RunProgram()
Re: Linux Reboot/Shutdown using PB app
Posted: Fri Oct 15, 2021 3:05 pm
by swhite
Hi
How exactly do you use sudo with RunProgram given that sudo needs a password?
Thanks,
Simon
Re: Linux Reboot/Shutdown using PB app
Posted: Fri Oct 15, 2021 4:56 pm
by useful
Re: Linux Reboot/Shutdown using PB app
Posted: Fri Oct 15, 2021 5:03 pm
by mk-soft
Part from RunAsAdmin and modified ...
not testet ...
Code: Select all
Procedure SuDo(user.s, passwd.s, program.s)
Protected cmd.s
If user = UserName()
cmd.s = "-c " + #DQUOTE$ + "echo " + passwd + " | sudo -S " + program + #DQUOTE$
Else
cmd.s = "-c " + #DQUOTE$ + "echo " + passwd + " | sudo -u " + user + " -S " + program + #DQUOTE$
EndIf
If RunProgram("bash", cmd, "")
;
Else
MessageRequester("Error", "Execute With Privileges!", #PB_MessageRequester_Error)
EndIf
EndProcedure
Re: Linux Reboot/Shutdown using PB app
Posted: Sat Oct 16, 2021 1:40 pm
by swhite
Thanks for these useful examples. I will give them a try.
Simon