C# calls adb command to read phone model and IMEI

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace ExecuteADB
{
public partial class Form1 : Form
{
//声明变量
string preimei, imei;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

/// <summary>
/// Click to get IMEI number
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
String cmd = Application.StartupPath + "\\adb\\adb.exe";
Process p = new Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo();
p.StartInfo.FileName = cmd;//Set the program name
p.StartInfo.Arguments = " shell getprop ro.product.model";
p.StartInfo.UseShellExecute = false; //Close the use of the shell
p.StartInfo.RedirectStandardInput = true; // redirect standard input
p.StartInfo.RedirectStandardOutput = true; // redirect standard output
p.StartInfo.RedirectStandardError = true;// redirect error output
p.StartInfo.CreateNoWindow = true;//Set the window not to be displayed
p.Start();
label2.Text = p.StandardOutput.ReadToEnd();
p.Close();
//////////// ///////////////
p.StartInfo = new System.Diagnostics.ProcessStartInfo();
p.StartInfo.FileName = cmd;//Set the program name
p.StartInfo.Arguments = " shell dumpsys iphonesubinfo";
p.StartInfo.UseShellExecute = false; //Close the use of the shell
p.StartInfo.RedirectStandardInput = true; //Redirect standard input
p.StartInfo.RedirectStandardOutput = true; //Redirect standard output
p.StartInfo. RedirectStandardError = true; //Redirect error output
p.StartInfo.CreateNoWindow = true;//Set the window not to be displayed
p.Start();
preimei = p.StandardOutput.ReadToEnd();

// string [] sArray = preimei.Split (new char [1] {'='});
// imei = sArray [2];
//textBox1.Text = imei.Trim ();
//p.Close ();
}
}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324831326&siteId=291194637