简介这是c#如何获得cpu硬盘的物理序列号的详细页面介绍了和c/c++有关的知识加入收藏请按键盘ctrl+D谢谢大家的观看!要查看更多有关信息
using system;
using systemruntimeinteropservices;
using systemmanagement;
namespace hardware
{
/// <summary>
/// hardware_mac 的摘要说明
/// </summary>
public class hardwareinfo
{
//取机器名
public string gethostname()
{
return dnsgethostname();
}
//取cpu编号
public string getcpuid()
{
try
{
managementclass mc = new managementclass(win_processor);
managementobjectcollection moc = mcgetinstances();
string strcpuid = null ;
foreach( managementobject mo in moc )
{
strcpuid = moproperties[processorid]valuetostring();
break;
}
return strcpuid;
}
catch
{
return ;
}
}//end method
//获取cpu序列号
public string getcpuid()
{
try
{
SystemManagementManagementObjectSearcher Wmi = new ManagementObjectSearcher ( SELECT * FROM Win_Processor );
string tmpUint_ = stringEmpty;
foreach(ManagementObject WmiObj in WmiGet())
{
tmpUint_ =WmiObj[ ProcessorId ]ToString();
}
thistextBoxText = tmpUint_;
thisgProgressBarValue ++;
}
catch(Exception ex)
{
throw new Exception(exToString());
}
}
//取第一块硬盘编号
public string getharddiskid()
{
try
{
managementobjectsearcher searcher = new managementobjectsearcher(select * from win_physicalmedia);
string strharddiskid = null ;
foreach(managementobject mo in searcherget())
{
strharddiskid = mo[serialnumber]tostring()trim();
break;
}
return strharddiskid ;
}
catch
{
return ;
}
}//end
//获取磁盘序列号
public string getharddiskid()
{
try
{
SystemManagementManagementObjectSearcher cmicWmi = new ManagementObjectSearcher( SELECT * FROM Win_DiskDrive );
SystemUInt tmpUint = ;
foreach(ManagementObject cmicWmiObj in cmicWmiGet())
{
tmpUint = ConvertToUInt(cmicWmiObj[ signature ]ToString());
}
thistextBoxText = tmpUintToString();
thisgProgressBarValue ++;
}
catch(Exception ex)
{
throw new Exception(exToString());
}
}
/// <summary>
/// 获取硬盘ID
/// </summary>
/// <returns> string </returns>
public string GetHDid()
{
string HDid = ;
using (ManagementClass cimobject = new ManagementClass(Win_DiskDrive))
{
ManagementObjectCollection moc = cimobjectGetInstances();
foreach (ManagementObject mo in moc)
{
HDid = (string)moProperties[Model]Value;
moDispose();
}
}
return HDidToString();
}
/// <summary>
/// 获取网卡硬件地址
/// </summary>
/// <returns> string </returns>
public string GetMoAddress()
{
string MoAddress = ;
using (ManagementClass mc = new ManagementClass(Win_NetworkAdapterConfiguration))
{
ManagementObjectCollection moc = mcGetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo[IPEnabled] == true)
MoAddress = mo[MacAddress]ToString();
moDispose();
}
}
return MoAddressToString();
}
}
}