获取电脑信息
private void Form1_Load(object sender, EventArgs e) { TreeNode root = new TreeNode("mycomputer"); treeView1.Nodes.Add(root); IDictionary<string, string> KeyValue = GetKeyValue(); foreach (string key in KeyValue.Keys) { TreeNode tn = new TreeNode(key); tn.Name = KeyValue[key]; root.Nodes.Add(tn); } treeView1.AfterSelect += (o1, e1) => { if (treeView1.SelectedNode.Text == "mycomputer") return; listBox1.Items.Clear(); ManagementObjectSearcher search = new ManagementObjectSearcher("select * from " + treeView1.SelectedNode.Name); foreach (ManagementObject mo in search.Get()) { foreach (PropertyData pd in mo.Properties) { if (pd.Value != null && pd.Value.ToString() != "") { string str = pd.Name + ":"; switch (pd.Value.GetType().ToString()) { case "System.String[]": foreach (string s in (string[])pd.Value) { str += s + " "; } str += "(System.String[])"; break; case "System.UInt16[]": foreach (UInt16 i in (UInt16[])pd.Value) { str += i.ToString() + " "; } str += "(System.UInt16[])"; break; default: str += pd.Value.ToString(); break; } listBox1.Items.Add(str); } } } }; //Microsoft.VisualBasic.Devices.ComputerInfo computer = new Microsoft.VisualBasic.Devices.ComputerInfo(); //listBox1.Items.Add(computer.AvailablePhysicalMemory / 1024 / 1024); //listBox1.Items.Add(computer.AvailableVirtualMemory / 1024 / 1024); //listBox1.Items.Add(computer.InstalledUICulture); //listBox1.Items.Add(computer.OSFullName); //listBox1.Items.Add(computer.OSPlatform); //listBox1.Items.Add(computer.OSVersion); //listBox1.Items.Add(computer.TotalPhysicalMemory / 1024 / 1024); //listBox1.Items.Add(computer.TotalVirtualMemory / 1024 / 1024); } public static IDictionary<string, string> GetKeyValue() { IDictionary<string, string> iDic = new Dictionary<string, string>(); iDic["Windows用户"] = "Win32_UserAccount"; iDic["用户组别"] = "Win32_Group"; iDic["当前进程"] = "Win32_Process"; iDic["系统服务"] = "Win32_Service"; iDic["系统驱动"] = "Win32_SystemDriver"; iDic["中央处理器"] = "Win32_Processor"; iDic["主板"] = "Win32_BaseBoard"; iDic["BIOS信息"] = "Win32_BIOS"; iDic["显卡"] = "Win32_VideoController"; iDic["音频设备"] = "Win32_SoundDevice"; iDic["物理内存"] = "Win32_PhysicalMemory"; iDic["磁盘"] = "Win32_LogicalDisk"; iDic["网络适配器"] = "Win32_NetworkAdapter"; iDic["网络协议"] = "Win32_NetworkProtocol"; iDic["打印与传真"] = "Win32_Printer"; iDic["键盘"] = "Win32_Keyboard"; iDic["鼠标"] = "Win32_PointingDevice"; iDic["串口"] = "Win32_SerialPort"; iDic["IDE控制器"] = "Win32_IDEController"; iDic["软驱控制器"] = "Win32_FloppyController"; iDic["USB控制器"] = "Win32_USBController"; iDic["SCSI控制器"] = "Win32_SCSIController"; iDic["PCMCIA卡控制器"] = "Win32_PCMCIAController"; iDic["1394控制器"] = "Win32_1394Controller"; iDic["即插即用设备"] = "Win32_PnPEntity"; return iDic; }