Note, You cannot change a running programs sudo level.
You have to either run the program as root (then ANY commands are done at root level) or it's not root.
When using the Exec or RunAsRoot command it creates a shell process (using pkexec for root) runs the command , then the process ends.
So IT WILL ask for root every time you run a command with pkexec or Desktop.RunAsRoot()
It is considered not-good to have a non-root application ask for sudo then quietly retain the privileges.
There are options...
Run the program as root.
Or you could use a Terminal gb.form.terminal then initiate it with TerminalView1.Exec("sudo","bash")
then the terminal has a root bash running in it until it is closed and multiple commands can be added to it.
or.
Put all your commands together in a temp file and run that.
Dim sCom As String = "apt update && apt upgrade -y"
File.Save("/tmp/exec", sCom)
Chmod "/tmp/exec" To "rwxr-xr-x"
Shell "pkexec env DISPLAY=" & Env["DISPLAY"] & "XAUTHORITY=" & Env["XAUTHORITY"] & " /tmp/exec" Wait
Kill "/tmp/exec"
note: i used "apt update -y" as the shell will not be interactive so you cannot enter and key text like y for yes to upgrade.