zoukankan      html  css  js  c++  java
  • 获取电脑信息

            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;
            }

  • 相关阅读:
    开源微信管家平台——JeeWx 捷微4.0 微服务版本发布,全新架构,全新UI,提供强大的图文编辑器
    JeeWx全新版本发布!捷微二代微信活动平台1.0发布!活动插件持续开源更新!
    JEECG 3.7.8 新版表单校验提示风格使用&升级方法(validform 新风格漂亮,布局简单)
    Java快速开发平台——JEECG 3.7.8 版本发布!我们的目标是有鱼丸也有粗面
    企业如何快速搭建小程序官网
    如何玩转小程序+公众号?手把手教你JeeWx小程序CMS与公众号关联
    deepClone deepCompare
    fiddler
    spy-debugger
    队列
  • 原文地址:https://www.cnblogs.com/fishes/p/2616240.html
Copyright © 2011-2022 走看看