获取cpu序列号,硬盘ID,网卡MAC地址
获取cpu序列号,硬盘ID,网卡MAC地址
using System.Management;
using System.Management.Instrumentation;
//获取硬盘ID 
String HDid; 
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"); 
ManagementObjectCollection moc1 = cimobject1.GetInstances(); 
foreach(ManagementObject mo in moc1) 
HDid = (string)mo.Properties["Model"].Value; 
Response.Write ("硬盘序列号:"+HDid.ToString ()); 
获取cpu序列号,硬盘ID,网卡MAC地址-老童
private void GetInfo()
{
string cpuInfo = "";//cpu序列号
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach(ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
Response.Write ("cpu序列号:"+cpuInfo.ToString ());
}
//获取硬盘ID
String HDid;
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach(ManagementObject mo in moc1)
{
HDid = (string)mo.Properties["Model"].Value;
Response.Write ("硬盘序列号:"+HDid.ToString ());
}
//获取网卡硬件地址
955882**********
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach(ManagementObject mo in moc2)
{
if((bool)mo["IPEnabled"] == true)
Response.Write("MAC address\t{0}"+mo["MacAddress"].ToString());
mo.Dispose();
}
}
usingSystem;
usingSystem.Runtime.InteropServices;
namespaceArLi.CommonPrj{
#regionhowusethis?
/*
stringsVol=getvol.GetVolOf("C");
*/
#endregion
publicclassgetvol{
[DllImport("kernel32.dll")]
private static externintGetVolumeInformation(
string lpRootPathName,
string lpVolumeNameBuffer,
int nVolumeNameSize,
refint lpVolumeSerialNumber,
int lpMaximumComponentLength,
int lpFileSystemFlags,
string lpFileSystemNameBuffer,
int nFileSystemNameSize
);
publicstaticstringGetVolOf(stringdrvID){
constintMAX_FILENAME_LEN=256;
硬盘序列号查询
intretVal=0;
inta=0;
intb=0;
stringstr1=null;
stringstr2=null;
inti=GetVolumeInformation(
drvID @":\",
str1,
MAX_FILENAME_LEN,
refretVal,
a,
b,
str2,
MAX_FILENAME_LEN
);
returnretVal.ToString("x");
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。