( 一 ).說明
取得裝置網卡的MAC地址和硬碟的卷標號
( 二 ).圖片樣本
( 三 ).代碼
using System;
using System.Management;
namespace NetCard
{
/// <summary>
/// 讀取裝置
/// </summary>
public class run
{
private ManagementClass mc;
private ManagementObjectCollection moc;
private ManagementObject disk;
public run( )
{
}
/// <summary>
/// 取得裝置網卡的MAC地址
/// </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>
/// 取得裝置硬碟的卷標號
/// </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( );
}
}
}