cmd에서 배터리 정보를 읽으려고합니다. 아래 그림과 같이 각 값을 추출하여 각각의 텍스트 상자에 넣을 수 있습니까?cmd에서 데이터 가져 오기, 값 분할 및 텍스트 상자에 삽입
Private Results As String
Private Delegate Sub delUpdate()
Private Finished As New delUpdate(AddressOf UpdateText)
Private Sub UpdateText()
TextBox11.Text = Results
End Sub
Private Sub batt_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
CMDThread.Start()
End Sub
Private Sub CMDAutomate()
Dim myprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
StartInfo.FileName = "cmd" 'starts cmd window
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.UseShellExecute = False 'required to redirect
StartInfo.CreateNoWindow = False 'creates no cmd window
myprocess.StartInfo = StartInfo
myprocess.Start()
Dim SR As System.IO.StreamReader = myprocess.StandardOutput
Dim SW As System.IO.StreamWriter = myprocess.StandardInput
SW.WriteLine("adb shell dumpsys battery") 'the command you wish to run.....
SW.WriteLine("exit") 'exits command prompt window
Results = SR.ReadToEnd 'returns results of the command window
SW.Close()
SR.Close()
'invokes Finished delegate, which updates textbox with the results text
Invoke(Finished)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim value As String = TextBox11.Text
Dim topic_start As String = topic_start = value.LastIndexOf("AC Powered:") + 1
Dim topic As String = value.Substring(topic_start, value.Length - topic_start)
TextBox1.Text = topic.ToString
End Sub
Button1
이미지에서 Get Battery Information
표지 할 것 :
여기 내 코드입니다.
데이터가 TextBox에 저장되는 방법을 보여줄 수 있습니다. 그러나 VbCrLf를 구분 기호로 사용하여 TextBox.Text를'.Split() '해야합니다. – Jimi
지금까지 어떤 코드를 작성 했습니까? 우리는 당신을 위해 전체 코드를 간단하게 작성할 수는 없습니다 – Sunil
모든 관련 정보는 다른 사이트에 링크되어 있지 않은 질문에 게시되어야합니다. –