首页 > 开发 > 综合 > 正文

C#取得设备网卡的MAC地址和硬盘的卷标号

2024-07-21 02:26:23
字体:
来源:转载
供稿:网友

( 一 ).说明
取得设备网卡的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( );
}
}
}
 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表