分享

C# 调用adb command 读取手机型号和IMEI

 _明心见性_ 2018-08-01

如下:

点击Button, label 显示获取的手机型号,texBox显示获取的手机IMEI号码。





代码如下:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10. namespace ExecuteADB
  11. {
  12. public partial class Form1 : Form
  13. {
  14. string preimei, imei;
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void Form1_Load(object sender, EventArgs e)
  20. {
  21. }
  22. private void button1_Click(object sender, EventArgs e)
  23. {
  24. String cmd = Application.StartupPath + "\\adb\\adb.exe";
  25. Process p = new Process();
  26. p.StartInfo = new System.Diagnostics.ProcessStartInfo();
  27. p.StartInfo.FileName = cmd;//设定程序名
  28. p.StartInfo.Arguments = " shell getprop ro.product.model";
  29. p.StartInfo.UseShellExecute = false; //关闭shell的使用
  30. p.StartInfo.RedirectStandardInput = true; //重定向标准输入
  31. p.StartInfo.RedirectStandardOutput = true; //重定向标准输出
  32. p.StartInfo.RedirectStandardError = true; //重定向错误输出
  33. p.StartInfo.CreateNoWindow = true;//设置不显示窗口
  34. p.Start();
  35. label2.Text = p.StandardOutput.ReadToEnd();
  36. p.Close();
  37. ///////////////////////////
  38. p.StartInfo = new System.Diagnostics.ProcessStartInfo();
  39. p.StartInfo.FileName = cmd;//设定程序名
  40. p.StartInfo.Arguments = " shell dumpsys iphonesubinfo";
  41. p.StartInfo.UseShellExecute = false; //关闭shell的使用
  42. p.StartInfo.RedirectStandardInput = true; //重定向标准输入
  43. p.StartInfo.RedirectStandardOutput = true; //重定向标准输出
  44. p.StartInfo.RedirectStandardError = true; //重定向错误输出
  45. p.StartInfo.CreateNoWindow = true;//设置不显示窗口
  46. p.Start();
  47. preimei = p.StandardOutput.ReadToEnd();
  1. //preimei
  2. //Phone Subscriber Info:
  3. //Phone Type = GSM
  4. //Device ID = 861699010825377

string[] sArray = preimei.Split(new char[1] { '=' }); 

imei = sArray[2]; 

textBox1.Text = imei.Trim(); 

                        p.Close(); 

} }}




    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多