(1). Description
Obtain the MAC address and hard disk volume of the NIC
(2). Image example
(3). Code
Using system;
Using system. Management;
Namespace netcard
{
/// <Summary>
/// Read the device
/// </Summary>
Public class run
{
Private managementclass MC;
Private managementobjectcollection MOC;
Private managementobject disk;
Public run ()
{
}
/// <Summary>
/// Obtain the MAC address of the device Nic
/// </Summary>
Public
String getnetcardmacaddress ()
{
MC = new managementclass ("win32_networkadapterconfiguration ");
MoC = mc. getinstances ();
String STR = "";
Foreach (managementobject Mo in MoC)
{
If (bool) Mo ["ipenabled"] = true)
STR = Mo ["macaddress"]. tostring ();
}
Return STR;
}
/// <Summary>
/// Obtain the volume ID of the device's hard disk
/// </Summary>
/// <Returns> </returns>
Public
String getdiskvolumeserialnumber ()
{
MC = new managementclass ("win32_networkadapterconfiguration ");
Disk = new managementobject ("win32_logicaldisk.deviceid =" C :"");
Disk. Get ();
Return disk. getpropertyvalue ("volumeserialnumber"). tostring ();
}
}
}