using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using cuiplus;
using System.Collections;
using System.Threading;
using System.Management;

namespace test
{
class Program
{
static void Main(string[] args)
{
//GetBaseBoardInfo();
//GetBiosInfo();
//GetPhysicalDiskInfo();
//GetNAConfigurationInfo();
//GetProcessorInfo();
//GetLogicalDiskInfo();
GetServiceInfo();
}
/// <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
{
}
}
}
}