Вы можете использовать cmd.exe
общаться с adb commands
увидеть мой пример кода.
Объявляя новый процесс и процесс INFO
Dim My_Process As New Process()
Dim My_Process_Info As New ProcessStartInfo()
Использование cmd.exe
в качестве имени файла моего процесса.
My_Process_Info.FileName = "cmd.exe"
В аргументе вы можете использовать команды adb, подобные этому.
My_Process_Info.Arguments = "/c adb devices"
/c
Осуществляет команду, указанную строку, а затем завершает свою работу.
Теперь установите рабочий каталог для adb.exe в cmd.exe. Не путайте, это то же самое, что и команда cd
. Установка нашего рабочего каталога на место, где находится ваш файл adb.exe.
My_Process_Info.WorkingDirectory = "Directory of your adb.exe file"
Теперь некоторые необходимые настройки для процесса.
My_Process_Info.CreateNoWindow = True ' Show or hide the process Window
My_Process_Info.UseShellExecute = False ' Don't use system shell to execute the process
My_Process_Info.RedirectStandardOutput = True ' Redirect (1) Output
My_Process_Info.RedirectStandardError = True ' Redirect non (1) Output
My_Process.EnableRaisingEvents = True ' Raise events
My_Process.StartInfo = My_Process_Info
Установка завершена, теперь начните процесс.
My_Process.Start()
Если вы хотите получить ответ/результат вашей отослано ADB команды вы можете использовать StandardOutput свойство процесса.
Dim Process_ErrorOutput As String = My_Process.StandardOutput.ReadToEnd() ' Stores the Error Output (If any)
Dim Process_StandardOutput As String = My_Process.StandardOutput.ReadToEnd() ' Stores the Standard Output (If any)
Пример Функция:
Function adb(ByVal Arguments As String) As String
Try
Dim My_Process As New Process()
Dim My_Process_Info As New ProcessStartInfo()
My_Process_Info.FileName = "cmd.exe" ' Process filename
My_Process_Info.Arguments = Arguments ' Process arguments
My_Process_Info.WorkingDirectory = "C:\Users\<Your User Name>\AppData\Local\Android\android-sdk\platform-tools" 'this directory can be different in your case.
My_Process_Info.CreateNoWindow = True ' Show or hide the process Window
My_Process_Info.UseShellExecute = False ' Don't use system shell to execute the process
My_Process_Info.RedirectStandardOutput = True ' Redirect (1) Output
My_Process_Info.RedirectStandardError = True ' Redirect non (1) Output
My_Process.EnableRaisingEvents = True ' Raise events
My_Process.StartInfo = My_Process_Info
My_Process.Start() ' Run the process NOW
Dim Process_ErrorOutput As String = My_Process.StandardOutput.ReadToEnd() ' Stores the Error Output (If any)
Dim Process_StandardOutput As String = My_Process.StandardOutput.ReadToEnd() ' Stores the Standard Output (If any)
' Return output by priority
If Process_ErrorOutput IsNot Nothing Then Return Process_ErrorOutput ' Returns the ErrorOutput (if any)
If Process_StandardOutput IsNot Nothing Then Return Process_StandardOutput ' Returns the StandardOutput (if any)
Catch ex As Exception
Return ex.Message
End Try
Return "OK"
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Usage:
'Get the list of connected devices.
MsgBox(adb("/c adb devices"))
'Connect your phone wirelessly using wifi (required phone I.P)
MsgBox(adb("/c adb disconnect 192.168.xx.xx:5555"))
'Get the list of connected devices.
MsgBox(adb("/c adb devices"))
'Put your phone on airplane mode.
MsgBox(adb("/c adb shell settings put global airplane_mode_on 1"))
End Sub
для стартеров '.Arguments' не должна включать в себя' .FileName'.команда, которую вы пытаетесь запустить, это 'adb adb shell ...' –
У меня вопрос. Можем ли мы сделать, как Shell («cmd.exe/c cd adb shell settings put global airplane_mode_on 0», AppWinStyle.Hide). Как это ? –