|
|
@@ -1,4 +1,5 @@
|
|
|
-using System;
|
|
|
+using Microsoft.Win32;
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
using System.Data;
|
|
|
@@ -16,9 +17,17 @@ namespace Y.Test.Views
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
-
|
|
|
private void TestComputerInfoForm_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
+ }
|
|
|
+ private void Print(string s)
|
|
|
+ {
|
|
|
+ textBox1.AppendText(s);
|
|
|
+ textBox1.AppendText(Environment.NewLine);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void GetHardInfo()
|
|
|
+ {
|
|
|
Print("UserName: " + ComputerInfoTool.UserName());
|
|
|
Print("登录用户名: " + ComputerInfoTool.UserName2());
|
|
|
|
|
|
@@ -39,17 +48,49 @@ namespace Y.Test.Views
|
|
|
Print("硬盘 序列号 " + x.Item1 + " 型号 " + x.Item2);
|
|
|
});
|
|
|
var osinfo = ComputerInfoTool.OsInfo();
|
|
|
- Print("操作系统: " + osinfo.Item1 + " " + osinfo.Item2+" "+osinfo.Item3);
|
|
|
+ Print("操作系统: " + osinfo.Item1 + " " + osinfo.Item2 + " " + osinfo.Item3);
|
|
|
Print("系统类型: " + ComputerInfoTool.SystemType());
|
|
|
Print("计算机名: " + ComputerInfoTool.MachineName());
|
|
|
Print("系统所有用户名: " + string.Join(",", ComputerInfoTool.UserNames()));
|
|
|
var boardinfo = ComputerInfoTool.BoardInfo();
|
|
|
Print("主板 制造商 " + boardinfo.Item1 + " 型号 " + boardinfo.Item2 + " 序列号 " + boardinfo.Item3);
|
|
|
}
|
|
|
- private void Print(string s)
|
|
|
+
|
|
|
+ private void GetSoftInfo()
|
|
|
{
|
|
|
- textBox1.AppendText(s);
|
|
|
- textBox1.AppendText(Environment.NewLine);
|
|
|
+ string temp = null, tempType = null;
|
|
|
+ object displayName = null, uninstallString = null, releaseType = null;
|
|
|
+ RegistryKey currentKey = null;
|
|
|
+ int softNum = 0;
|
|
|
+ RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");//获取指定路径下的键
|
|
|
+ try
|
|
|
+ {
|
|
|
+ foreach (string item in pregkey.GetSubKeyNames()) //循环所有子键
|
|
|
+ {
|
|
|
+ currentKey = pregkey.OpenSubKey(item);
|
|
|
+ displayName = currentKey.GetValue("DisplayName"); //获取显示名称
|
|
|
+ uninstallString = currentKey.GetValue("UninstallString"); //获取卸载字符串路径
|
|
|
+ releaseType = currentKey.GetValue("ReleaseType"); //发行类型,值是Security Update为安全更新,Update为更新
|
|
|
+ bool isSecurityUpdate = false;
|
|
|
+ if (releaseType != null)
|
|
|
+ {
|
|
|
+ tempType = releaseType.ToString();
|
|
|
+ if (tempType == "Security Update" || tempType == "Update")
|
|
|
+ isSecurityUpdate = true;
|
|
|
+ }
|
|
|
+ if (!isSecurityUpdate && displayName != null && uninstallString != null)
|
|
|
+ {
|
|
|
+ softNum++;
|
|
|
+ temp += displayName.ToString() + Environment.NewLine;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception E)
|
|
|
+ {
|
|
|
+ MessageBox.Show(E.Message.ToString());
|
|
|
+ }
|
|
|
+ richTextBox1.Text = "您本机安装了" + softNum.ToString() + "个" + Environment.NewLine + temp;
|
|
|
+ pregkey.Close();
|
|
|
}
|
|
|
}
|
|
|
}
|