- /// <summary>
- /// 主板信息
- /// </summary>
- public static void GetBaseBoardInfo()
- {
- try
- {
- Console.WriteLine(“主板信息”);
- ManagementObjectSearcher searcher =
- new ManagementObjectSearcher(“Select * From Win32_BaseBoard”);
- foreach (ManagementObject mo in searcher.Get())
- {
- // mo[“Manufacturer”],制造商,如“On-data”(昂达)
- // mo[“Product”],型号,如“KT400A-8235”
- // mo[“SerialNumber”],序列号
- Console.WriteLine( mo[“Manufacturer”]);
- Console.WriteLine(mo[“Product”]);
- Console.WriteLine(mo[“SerialNumber”]);
- }
- }
- catch
- {
- }
- }
- /// <summary>
- /// BIOS信息
- /// </summary>
- public static void GetBiosInfo()
- {
- try
- {
- Console.WriteLine(“BIOS信息”);
- ManagementObjectSearcher searcher =
- new ManagementObjectSearcher(“Select * From Win32_BIOS”);
- foreach (ManagementObject mo in searcher.Get())
- {
- // mo[“Manufacturer”],制造商,如“Phoenix Technologies, LTD”
- // mo[“SerialNumber”],序列号
- Console.WriteLine(mo[“Manufacturer”]);
- Console.WriteLine(mo[“SerialNumber”]);
- }
- }
- catch
- {
- }
- }
- /// <summary>
- /// 物理磁盘信息
- /// </summary>
- public static void GetPhysicalDiskInfo()
- {
- try
- {
- Console.WriteLine(“物理磁盘信息”);
- ManagementObjectSearcher searcher =
- new ManagementObjectSearcher(“Select * From Win32_DiskDrive”);
- foreach (ManagementObject mo in searcher.Get())
- {
- // mo[“MediaType”],类型,如“Fixed hard disk media”
- // mo[“SizeBytes “],容量,如“80023749120”(字节)
- Console.WriteLine(mo[“MediaType”]);
- Console.WriteLine(mo[“SizeBytes”]);
- }
- }
- catch
- {
- }
- }
- /// <summary>
- /// 网卡配置信息
- /// </summary>
- public static void GetNAConfigurationInfo()
- {
- try
- {
- Console.WriteLine(“网卡配置信息”);
- ManagementObjectSearcher searcher =
- new ManagementObjectSearcher(“Select * From Win32_NetworkAdapterConfiguration”);
- foreach (ManagementObject mo in searcher.Get())
- {
- // mo[“IPAddress”],IP地址
- // mo[“DefaultIPGateway”],默认网关
- // mo[“DNSServerSearchOrder”],DNS地址,如果有备用则会以数组形式返回
- // mo[“IPSubnet”],子网掩码
- // mo[“MACAddress”],MAC地址
- Console.WriteLine(mo[“IPAddress”]);
- Console.WriteLine(mo[“DefaultIPGateway”]);
- Console.WriteLine(mo[“DNSServerSearchOrder”]);
- Console.WriteLine(mo[“IPSubnet”]);
- Console.WriteLine(mo[“MACAddress”]);
- }
- }
- catch
- {
- }
- }
- /// <summary>
- /// CPU信息
- /// </summary>
- public static void GetProcessorInfo()
- {
- try
- {
- Console.WriteLine(“CPU信息”);
- ManagementObjectSearcher searcher =
- new ManagementObjectSearcher(“Select * From Win32_Processor”);
- foreach (ManagementObject mo in searcher.Get())
- {
- // mo[“L2CacheSize”],二级缓存,如“512”
- // mo[“Manufacturer”],制造商,如“AuthenticAMD”
- // mo[“MaxClockSpeed”],主频,如“1824”(1.824G)
- // mo[“ProcessorId”],ID,如“0383F9FF000006A0”
- Console.WriteLine(mo[“L2CacheSize”]);
- Console.WriteLine(mo[“Manufacturer”]);
- Console.WriteLine(mo[“MaxClockSpeed”]);
- Console.WriteLine(mo[“ProcessorId”]);
- }
- }
- catch
- {
- }
- }
- /// <summary>
- /// 逻辑磁盘信息
- /// </summary>
- public static void GetLogicalDiskInfo()
- {
- try
- {
- Console.WriteLine(“逻辑磁盘信息”);
- ManagementObjectSearcher searcher =
- new ManagementObjectSearcher(“Select * From Win32_LogicalDisk”);
- foreach (ManagementObject mo in searcher.Get())
- {
- // mo[“FileSystem”],文件系统,如“FAT32”
- // mo[“FreeSpace”],剩余空间,如“4554891264”(4G多)
- // mo[“Name”],卷标,如“C:”
- // mo[“Size”],大小,如“10476945408”(10G)
- Console.WriteLine(mo[“FileSystem”]);
- Console.WriteLine(mo[“FreeSpace”]);
- Console.WriteLine(mo[“Name”]);
- Console.WriteLine(mo[“Size”]);
- }
- }
- catch
- {
- }
- }
- /// <summary>
- /// 服务信息
- /// </summary>
- public static void GetServiceInfo()
- {
- try
- {
- Console.WriteLine(“服务信息”);
- ManagementObjectSearcher s = new ManagementObjectSearcher(“SELECT * FROM Win32_Service”);
- foreach (ManagementObject service in s.Get())
- {
- Console.WriteLine(service.ToString());
- }
- }
- catch
- {
- }
- }
以上用到如下内容的查询:
Win32_BaseBoard//主板信息
Win32_BIOS//BIOS信息
Win32_DiskDrive//物理磁盘信息
Win32_NetworkAdapterConfiguration//网卡配置信息
Win32_Processor//CPU信息
Win32_LogicalDisk//逻辑磁盘信息
Win32_Service//服务信息
其他可参考MSDN中的WMI介绍:
Operating System Classes
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/39129.html