Search code examples
batch-fileadbroot

How to verify root from adb shell?


In my script I have the following code:

for /f "delims=" %%a in ('adb -s devicename shell su') do @set res=%%a
echo %res%

But I get no output. How to properly check for su availability from a batch script?


Solution

  • set uid=
    for /f "delims=" %%a in ('adb -s devicename shell "su 0 id -u 2>/dev/null"') do set uid=%%a
    echo %uid%
    

    %uid% will be 0 if su is available