So I got some code which runs on a USB connect event. If and android device is detected it runs some build prop related code. However... It only manages to return the android version and nothing else. The code is below.
private void Main_Shown(object sender, EventArgs e)
{
var watcher = new ManagementEventWatcher();
var query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2");
watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
watcher.Query = query;
watcher.Start();
}
private void watcher_EventArrived(object sender, EventArrivedEventArgs e)
{
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.RedirectStandardInput = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "adb.exe";
startInfo.Arguments = "shell getprop ro.build.version.release";
process = Process.Start(startInfo);
device.Invoke((MethodInvoker)(() => device.Text = process.StandardOutput.ReadToEnd()));
Process p = new System.Diagnostics.Process();
ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
si.RedirectStandardInput = false;
si.CreateNoWindow = true;
si.RedirectStandardOutput = true;
si.RedirectStandardError = false;
si.UseShellExecute = false;
si.FileName = "adb.exe";
si.Arguments = "shell getprop ro.product.model";
p = Process.Start(si);
AV.Invoke((MethodInvoker)(() => AV.Text = process.StandardOutput.ReadToEnd()));
Process pr = new System.Diagnostics.Process();
ProcessStartInfo siy = new System.Diagnostics.ProcessStartInfo();
siy.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
siy.RedirectStandardInput = false;
siy.CreateNoWindow = true;
siy.RedirectStandardOutput = true;
siy.RedirectStandardError = false;
siy.UseShellExecute = false;
siy.FileName = "adb.exe";
siy.Arguments = "shell getprop ro.product.name";
pr = Process.Start(siy);
name.Invoke((MethodInvoker)(() => name.Text = process.StandardOutput.ReadToEnd()));
This should be returning 3 values and placing them into the respective labels. However only one is returned. Is there any way I can improve the code to do this?
And the shell getprop ro.*
worked in an earlier build and had not been changed...
Turns out I was being a derp. I had the same process set for everything and it threw errors. Rookie mistake really. I got too caught up in my own hype... New code
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.RedirectStandardInput = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "adb.exe";
startInfo.Arguments = "shell getprop ro.build.version.release";
process = Process.Start(startInfo);
device.Invoke((MethodInvoker)(() => device.Text = process.StandardOutput.ReadToEnd()));
Process p = new System.Diagnostics.Process();
ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
si.RedirectStandardInput = false;
si.CreateNoWindow = true;
si.RedirectStandardOutput = true;
si.RedirectStandardError = false;
si.UseShellExecute = false;
si.FileName = "adb.exe";
si.Arguments = "shell getprop ro.product.model";
p = Process.Start(si);
AV.Invoke((MethodInvoker)(() => AV.Text = p.StandardOutput.ReadToEnd()));
Process pr = new System.Diagnostics.Process();
ProcessStartInfo siy = new System.Diagnostics.ProcessStartInfo();
siy.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
siy.RedirectStandardInput = false;
siy.CreateNoWindow = true;
siy.RedirectStandardOutput = true;
siy.RedirectStandardError = false;
siy.UseShellExecute = false;
siy.FileName = "adb.exe";
siy.Arguments = "shell getprop ro.product.name";
pr = Process.Start(siy);
name.Invoke((MethodInvoker)(() => name.Text = pr.StandardOutput.ReadToEnd()));