计算机信息检测

public void InsertInfo(string Key, ref ListView lst, bool DontInsertNull)
        {
            lst.Items.Clear();
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + Key);
            try
            {
                foreach (ManagementObject share in searcher.Get())
                {
                    ListViewGroup grp;
                    try
                    {
                        grp = lst.Groups.Add(share["Name"].ToString(), share["Name"].ToString());
                    }
                    catch
                    {
                        grp = lst.Groups.Add(share.ToString(), share.ToString());
                    }

                    if (share.Properties.Count <= 0)
                    {
                        MessageBox.Show("No Information Available", "No Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    foreach (PropertyData PC in share.Properties)
                    {
                        ListViewItem item = new ListViewItem(grp);
                        if (lst.Items.Count % 2 != 0)
                            item.BackColor = Color.White;
                        else
                            item.BackColor = Color.WhiteSmoke;
                        item.Text =ConvertStr(PC.Name);
                        if (PC.Value != null && PC.Value.ToString() != "")
                        {
                            switch (PC.Value.GetType().ToString())
                            {
                                case "System.String[]":
                                    string[] str = (string[])PC.Value;
                                    string str2 = "";
                                    foreach (string st in str)
                                        str2 += st + " ";
                                    item.SubItems.Add(str2);
                                    break;
                                case "System.UInt16[]":
                                    ushort[] shortData = (ushort[])PC.Value;
                                    string tstr2 = "";
                                    foreach (ushort st in shortData)
                                        tstr2 += st.ToString() + " ";
                                    item.SubItems.Add(tstr2);
                                    break;
                                default:
                                    item.SubItems.Add(PC.Value.ToString());
                                    break;
                            }
                        }
                        else
                        {
                            if (!DontInsertNull)
                                item.SubItems.Add("没有信息");
                            else
                                continue;
                        }

                        lst.Items.Add(item);
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }


 

private void GetInfo()
        {
            PublicClass pc = new PublicClass();
            switch (selectTxt)
            {
                case "Windows信息":
                    pc.getInfo1(listView1);
                    break;
                case "Windows用户":
                    pc.InsertInfo("Win32_UserAccount", ref listView1, true);
                    break;
                case "用户组别":
                    pc.InsertInfo("Win32_Group", ref listView1, true);
                    break;
                case "当前进程":
                    pc.InsertInfo("Win32_Process", ref listView1, true);
                    break;
                case "系统服务":
                    pc.InsertInfo("Win32_Service", ref listView1, true);
                    break;
                case "系统驱动":
                    pc.InsertInfo("Win32_SystemDriver", ref listView1, true);
                    break;
                case "中央处理器":
                    pc.InsertInfo("Win32_Processor", ref listView1, true);
                    break;
                case "主板":
                    pc.InsertInfo("Win32_BaseBoard", ref listView1, true);
                    break;
                case "BIOS信息":
                    pc.InsertInfo("Win32_BIOS", ref listView1, true);
                    break;
                case "显卡":
                    pc.InsertInfo("Win32_VideoController", ref listView1, true);
                    break;
                case "音频设备":
                    pc.InsertInfo("Win32_SoundDevice", ref listView1, true);
                    break;
                case "物理内存":
                    pc.InsertInfo("Win32_PhysicalMemory", ref listView1, true);
                    break;
                case "磁盘":
                    pc.InsertInfo("Win32_LogicalDisk", ref listView1, true);
                    break;
                case "网络适配器":
                    pc.InsertInfo("Win32_NetworkAdapter", ref listView1, true);
                    break;
                case "网络协议":
                    pc.InsertInfo("Win32_NetworkProtocol", ref listView1, true);
                    break;
                case "打印与传真":
                    pc.InsertInfo("Win32_Printer", ref listView1, true);
                    break;
                case "键盘":
                    pc.InsertInfo("Win32_Keyboard", ref listView1, true);
                    break;
                case "鼠标":
                    pc.InsertInfo("Win32_PointingDevice", ref listView1, true);
                    break;
                case "串口":
                    pc.InsertInfo("Win32_SerialPort", ref listView1, true);
                    break;
                case "IDE控制器":
                    pc.InsertInfo("Win32_IDEController", ref listView1, true);
                    break;
                case "软驱控制器":
                    pc.InsertInfo("Win32_FloppyController", ref listView1, true);
                    break;
                case "USB控制器":
                    pc.InsertInfo("Win32_USBController", ref listView1, true);
                    break;
                case "SCSI控制器":
                    pc.InsertInfo("Win32_SCSIController", ref listView1, true);
                    break;
                case "PCMCIA卡控制器":
                    pc.InsertInfo("Win32_PCMCIAController", ref listView1, true);
                    break;
                case "1394控制器":
                    pc.InsertInfo("Win32_1394Controller", ref listView1, true);
                    break;
                case "即插即用设备":
                    pc.InsertInfo("Win32_PnPEntity", ref listView1, true);
                    break;
                    

            }
            
        }


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值