TestComputerInfoForm.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using Y.Utils.WindowsUtils.InfoUtils;
  11. namespace Y.Test.Views
  12. {
  13. public partial class TestComputerInfoForm : Form
  14. {
  15. public TestComputerInfoForm()
  16. {
  17. InitializeComponent();
  18. }
  19. private void TestComputerInfoForm_Load(object sender, EventArgs e)
  20. {
  21. }
  22. private void Print(string s)
  23. {
  24. textBox1.AppendText(s);
  25. textBox1.AppendText(Environment.NewLine);
  26. }
  27. private void GetHardInfo()
  28. {
  29. Print("UserName: " + ComputerInfoTool.UserName());
  30. Print("登录用户名: " + ComputerInfoTool.UserName2());
  31. Print("UserDomainName: " + ComputerInfoTool.UserDomainName());
  32. Print("TickCount: " + ComputerInfoTool.TickCount());
  33. Print("ProcessorCount: " + ComputerInfoTool.ProcessorCount());
  34. Print("OSVersion: " + ComputerInfoTool.OSVersion());
  35. Print("Is64BitOperatingSystem: " + ComputerInfoTool.Is64BitOperatingSystem());
  36. Tuple<string, string> cpuinfo = ComputerInfoTool.CpuInfo();
  37. Print("CPU 序列号 " + cpuinfo.Item1 + " 型号 " + cpuinfo.Item2);
  38. Print("显卡信息: " + string.Join(",", ComputerInfoTool.GraphicsCardInfo()));
  39. Print("声卡信息: " + string.Join(",", ComputerInfoTool.SoundCardModel()));
  40. Print("内存: " + ComputerInfoTool.AvailablePhysicalMemory() + " / " + ComputerInfoTool.TotalPhysicalMemory());
  41. List<Tuple<string, string>> harddiskinfo = ComputerInfoTool.HardDiskInfo();
  42. harddiskinfo.ForEach(x =>
  43. {
  44. Print("硬盘 序列号 " + x.Item1 + " 型号 " + x.Item2);
  45. });
  46. var osinfo = ComputerInfoTool.OsInfo();
  47. Print("操作系统: " + osinfo.Item1 + " " + osinfo.Item2 + " " + osinfo.Item3);
  48. Print("系统类型: " + ComputerInfoTool.SystemType());
  49. Print("计算机名: " + ComputerInfoTool.MachineName());
  50. Print("系统所有用户名: " + string.Join(",", ComputerInfoTool.UserNames()));
  51. var boardinfo = ComputerInfoTool.BoardInfo();
  52. Print("主板 制造商 " + boardinfo.Item1 + " 型号 " + boardinfo.Item2 + " 序列号 " + boardinfo.Item3);
  53. }
  54. private void GetSoftInfo()
  55. {
  56. string temp = null, tempType = null;
  57. object displayName = null, uninstallString = null, releaseType = null;
  58. RegistryKey currentKey = null;
  59. int softNum = 0;
  60. RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");//获取指定路径下的键
  61. try
  62. {
  63. foreach (string item in pregkey.GetSubKeyNames()) //循环所有子键
  64. {
  65. currentKey = pregkey.OpenSubKey(item);
  66. displayName = currentKey.GetValue("DisplayName"); //获取显示名称
  67. uninstallString = currentKey.GetValue("UninstallString"); //获取卸载字符串路径
  68. releaseType = currentKey.GetValue("ReleaseType"); //发行类型,值是Security Update为安全更新,Update为更新
  69. bool isSecurityUpdate = false;
  70. if (releaseType != null)
  71. {
  72. tempType = releaseType.ToString();
  73. if (tempType == "Security Update" || tempType == "Update")
  74. isSecurityUpdate = true;
  75. }
  76. if (!isSecurityUpdate && displayName != null && uninstallString != null)
  77. {
  78. softNum++;
  79. temp += displayName.ToString() + Environment.NewLine;
  80. }
  81. }
  82. }
  83. catch (Exception E)
  84. {
  85. MessageBox.Show(E.Message.ToString());
  86. }
  87. richTextBox1.Text = "您本机安装了" + softNum.ToString() + "个" + Environment.NewLine + temp;
  88. pregkey.Close();
  89. }
  90. }
  91. }