国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

c#獲取硬件資源

2019-11-17 04:03:57
字體:
來源:轉載
供稿:網友
c#通過WMI獲取硬件資源代碼:

     public class GetSystemInfo
    {
        PRivate ManagementClass mc;
        private ManagementObjectCollection moc;

        public GetSystemInfo()
        { }

        public string GetHardDiskInfo()
        {
            mc = new ManagementClass("Win32_DiskDrive");
            moc = mc.GetInstances();
            String HardDiskInfo = string.Empty;
            foreach (ManagementObject mo in moc)
            {
                HardDiskInfo = "硬盤類型:" + mo.Properties["Manufacturer"].Value.ToString() + "/n" +
                        "   硬盤型號:" + mo.Properties["Model"].Value.ToString() + "/n" +
                        "   硬盤容量:" + mo.Properties["Size"].Value.ToString() + "/n" +
                        "   硬盤序列號:" + mo.Properties["PNPDeviceID"].Value.ToString() + "/n" +
                        "   硬盤分區數:" + mo.Properties["Partitions"].Value.ToString() + "/n" +
                        "   字節/扇:" + mo.Properties["BytesPerSector"].Value.ToString() + "/n" +
                        "   扇區/道:" + mo.Properties["SectorsPerTrack"].Value.ToString() + "/n" +
                        "   磁道/族:" + mo.Properties["TracksPerCylinder"].Value.ToString() + "/n" +
                        "   總扇區:" + mo.Properties["TotalSectors"].Value.ToString() + "/n" +
                        "   總磁道:" + mo.Properties["TotalTracks"].Value.ToString() + "/n" +
                        "   總族數:" + mo.Properties["TotalCylinders"].Value.ToString() + "/n" +
                        "   總磁頭:" + mo.Properties["TotalHeads"].Value.ToString();
            }
            moc = null;
            mc = null;
            return HardDiskInfo;
        }

        public string GetBIOSInfo()
        {
            mc = new ManagementClass("Win32_BIOS");
            moc = mc.GetInstances();
            String BIOSInfo = null;
            foreach (ManagementObject mo in moc)
            {
                BIOSInfo = "BIOS廠商:" + mo.Properties["Manufacturer"].Value.ToString() + "/n" +
                        "   BIOS版本:" + mo.Properties["Version"].Value.ToString();

            }
            moc = null;
            mc = null;
            return BIOSInfo;
        }

        public string GetVideoCardInfo()
        {
            mc = new ManagementClass("Win32_VideoController");
            moc = mc.GetInstances();
            String VideoCardInfo = string.Empty;
            foreach (ManagementObject mo in moc)
            {
                foreach (PropertyData pd in mo.Properties)
                {
                    if (pd.Name.Equals("Name"))
                    {
                        VideoCardInfo = VideoCardInfo + "   顯卡名稱:" + pd.Value + "/n";
                    }
                    else if (pd.Name.Equals("PNPDeviceID"))
                    {
                        VideoCardInfo = VideoCardInfo + "   顯卡序列號:" + pd.Value + "/n";
                    }
                    else if (pd.Name.Equals("DeviceID"))
                    {
                        VideoCardInfo = VideoCardInfo + "   顯卡ID:" + pd.Value + "/n";
                    }
                    else if (pd.Name.Equals("Status"))
                    {
                        VideoCardInfo = VideoCardInfo + "   顯卡狀態:" + pd.Value + "/n";
                    }
                    else if (pd.Name.Equals("VideoModeDescription"))
                    {
                        VideoCardInfo = VideoCardInfo + "   顯卡運行模式:" + pd.Value;
                    }
                }
            }
            moc = null;
            mc = null;
            return VideoCardInfo;
        }

        public string GetUSBInfo()
        {
            mc = new ManagementClass("Win32_USBController");
            moc = mc.GetInstances();
            String USBInfo = string.Empty;
            foreach (ManagementObject mo in moc)
            {
                foreach (PropertyData pd in mo.Properties)
                {
                    if (pd.Name.Equals("Manufacturer"))
                    {
                        USBInfo = USBInfo + "   廠商:" + pd.Value + "/n";
                    }
                    else if (pd.Name.Equals("Name"))
                    {
                        USBInfo = USBInfo + "   USB控制器名稱:" + pd.Value + "/n";
                    }
                    else if (pd.Name.Equals("Status"))
                    {
                        USBInfo = USBInfo + "   USB狀態:" + pd.Value + "/n";
                    }
                    else if (pd.Name.Equals("PNPDeviceID"))
                    {
                        USBInfo = USBInfo + "   USB控制器ID:" + pd.Value;
                    }
                }
            }
            moc = null;
            mc = null;
            return USBInfo;
        }

        public string GetCPUInfo()
        {
            mc = new ManagementClass("Win32_Processor");
            moc = mc.GetInstances();
            String CPUInfo = string.Empty;
            foreach (ManagementObject mo in moc)
            {
                CPUInfo = "CPU頻率:" + mo.Properties["currentClockSpeed"].Value.ToString() + "/n" +
                        "   CPU序號:" + mo.Properties["ProcessorID"].Value.ToString() + "/n" +
                        "   CPU主頻:" + mo.Properties["ExtClock"].Value.ToString() + "/n" +
                        "   32位數據寬度:" + mo.Properties["AddressWidth"].Value.ToString() + "/n" +
                        "   32位型號描述:" + mo.Properties["Description"].Value.ToString() + "/n" +
                        "   CPU廠商:" + mo.Properties["Manufacturer"].Value.ToString();
            }
            moc = null;
            mc = null;
            return CPUInfo;
        }

        public string GetMemoryInfo()
        {
            mc = new ManagementClass("Win32_PhysicalMemory");
            moc = mc.GetInstances();
            String MemoryInfo = string.Empty;
            foreach (ManagementObject mo in moc)
            {
                MemoryInfo = "內存名:" + mo.Properties["Name"].Value.ToString() + "/n" +
                            //"   內存序列號:" + mo.Properties["PartNumber"].Value.ToString() + "/n" +
                            //"   Version:" + mo.Properties["Version"].Value.ToString() + "/n" +
                            "   TotalWidth:" + mo.Properties["TotalWidth"].Value.ToString();
            }
            moc = null;
            mc = null;
            return MemoryInfo;
        }
    }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 兴和县| 庐江县| 喀喇沁旗| 德州市| 萨嘎县| 蕉岭县| 雷山县| 大宁县| 旌德县| 蕉岭县| 英德市| 大理市| 漳浦县| 泉州市| 南安市| 阿尔山市| 彭山县| 治多县| 翁源县| 白朗县| 清苑县| 南雄市| 德庆县| 东乌珠穆沁旗| 安陆市| 米脂县| 鄂尔多斯市| 故城县| 临安市| 石门县| 华阴市| 洛隆县| 靖边县| 招远市| 抚远县| 陇西县| 宝山区| 七台河市| 南召县| 修文县| 武安市|