Android Tutorial Running shell commands as SuperUser

Status
Not open for further replies.
if you want run any shell command as superuser(you must have rooted phone), try this:
B4X:
Dim Command, Runner As String
Dim StdOut, StdErr As StringBuilder
Dim Result As Int
Dim Ph As Phone
Runner = File.Combine(File.DirInternalCache, "runner")
Command = File.Combine(File.DirInternalCache, "command")
File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
File.WriteString(File.DirInternalCache, "command", "modprobe cifs" & CrLf & "modprobe aufs" & CrLf & "exit") 'Any commands via crlf, and exit at end 
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
Msgbox(StdOut.tostring, "")
 

anaylor01

Well-Known Member
Licensed User
I put this script in a button click event and I get the error Object should first be initialized (StringBuilder). on this line.
B4X:
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
 
Last edited:

anaylor01

Well-Known Member
Licensed User
I put the code exactly as it is in the button click event. The code has Dim Ph as phone. Is there something else I need to do ?
 

anaylor01

Well-Known Member
Licensed User
Sorry but I am new to this and am still figuring things out. So if you could show me the code I would appreciate it. Thanks.
 

anaylor01

Well-Known Member
Licensed User
Maybe you can help me with this. I am trying to remove the SMS limit. I found some information on the net but am having trouble getting it to work. How to Increase the SMS Limit on AndroidIt keeps saying "No Such Table". Here is what I have so far.
B4X:
SQL1.Initialize(File.DirInternal, "settings.db", True)
lblsendingto.Text =  SQL1.ExecQuerySingleResult("SELECT count(name) FROM secure")'system name secure name gservices Name value
 

fpdianzen

Member
Licensed User
hi!

hi thank you for this info, yet im still confused.
i wanted to enter this, shell commands.
what format should i use? :sign0104:


B4X:
#su
#setprop ctl.stop adbd
 

madSac

Active Member
Licensed User
One ques.
How can i check if a device has SuperUser or not ?
or say device is rooted or not ?
 

madSac

Active Member
Licensed User
You can run a script that will fail on unrooted devices and check the error string.

Any basic command which will have no effect ?
I don't know anything about shell commands but I came to know its potential in this forum only.Even thought I rooted my phone much before but never tried to run shell commands.
 

madSac

Active Member
Licensed User
whenever i use this code
B4X:
Dim p As Phone
Dim sb,se As StringBuilder
sb.Initialize
se.Initialize
p.Shell("ls",Null,sb,se)
Log(sb)
Log(se)
i get
B4X:
opendir failed, Permission denied
in logs.
i have setting to prompt for access in SU but i get No prompt for superuser permission and this error in log.Am i mistaken somewhere ?
 
Status
Not open for further replies.
Top