日期:2014-05-19  浏览次数:20999 次

请教:如何读取本地机的网卡号/硬盘序列号/电脑名称?
我做的是winform程序。请教如何读取本地机的:
1.   网卡号
2.   硬盘序列号
3.   电脑名称?

预先   感谢各位的帮助!

------解决方案--------------------
获取硬件信息源代码:
http://www.codeproject.com/cs/system/GetHardwareInformation/GetHardwareInfo_Code.zip


获取硬件信息演示程序:
http://www.codeproject.com/cs/system/GetHardwareInformation/GetHardwareInfo_Exe.zip

汉化
http://www.msproject.cn/Article/GetHardwareInformation.aspx

利用using System.Management类来获取相应的硬件知识
------解决方案--------------------
/// <summary>
/// 等到计算机名
/// </summary>
/// <returns> </returns>
public static string GetComputerName()
{
return Dns.GetHostName();
}

/// <summary>
/// 得到网卡号
/// </summary>
/// <returns> </returns>
public static string GetMachineMac()
{
string lcRetVal = " ";
try
{
string text2 = "select AdapterType, DeviceID, ProductName, ServiceName, MACAddress from Win32_NetworkAdapter ";
WqlObjectQuery query1 = new WqlObjectQuery(text2);
ManagementObjectCollection collection1 = new ManagementObjectSearcher(query1).Get();
foreach (ManagementObject obj1 in collection1)
{
lcRetVal += ((lcRetVal == " ") ? " " : ", ") + obj1[ "MACAddress "];
}
return lcRetVal;
}
catch (Exception)
{
}
return lcRetVal;
}

/// <summary>
/// 得到硬盘序列号
/// </summary>
/// <returns> </returns>
public static string GetDriveSerialNum()
{
String lcRetVal= " ";
ManagementClass cimobject = new ManagementClass( "Win32_DiskDrive ");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach (ManagementObject mo in moc)
{
lcRetVal +=(lcRetVal== " "? " ": "-- ")+ (string)mo.Properties[ "Model "].Value;
}

return lcRetVal;
}
/// <summary>
/// 得到硬盘剩余大小
/// </summary>
/// <param name= "pcDisName "> </param>
/// <returns> </returns>
public ulong GetDiskSpace(string pcDisName)
{
ManagementClass diskClass = new ManagementClass( "Win32_LogicalDisk ");
ManagementObjectCollection disks = diskClass.GetInstances();
ulong space = 0;
foreach (ManagementObject disk in disks)
{
if (disk[ "Name "].ToString().ToUpper() == pcDisName.ToUpper())
{
space = (ulong)disk[ "FreeSpace "];
}
}
return space;
}
------解决方案--------------------
获取硬件信息源代码:
http://www.codeproject.com/cs/system/GetHardwareInformation/GetHardwareInfo_Code.zip

获取硬件信息演示程序:
http://www.codeproject.com/cs/system/GetHardwareInformation/GetHardwareIn