MAC获取绑订
来源:互联网 发布:微信62登录脚本源码 编辑:程序博客网 时间:2024/04/29 01:03
建立一个类.然后读取信息.调用代码如下.
HardInfoClass myclass=new HardInfoClass();
textBox1.Text=myclass.GetHardDiskID();
textBox2.Text=myclass.GetCpuID();
textBox3.Text=myclass.GetNetCardMAC();
textBox4.Text=myclass.GetNetCardIP();
textBox5.Text=myclass.GetHostName();
textBox6.Text=myclass.GetVolOf("D");//C盘58c6b679跟D盘6ed62864不一样
//textBox7.Text=myclass.GetHashCode();
//textBox8.Text=myclass.GetCpuID();
类HardInfoClass代码如下
using System;
using System.Net;
using System.Runtime.InteropServices;
using System.Management; //需要在解决方案中引用System.Management.DLL文件
namespace FileTransLate.PCStatus
{
/// <summary>
/// HardInfoClass 的摘要说明。
/// </summary>
public class HardInfoClass
{
[DllImport("kernel32.dll")]
private static extern int GetVolumeInformation(
string lpRootPathName,
string lpVolumeNameBuffer,
int nVolumeNameSize,
ref int lpVolumeSerialNumber,
int lpMaximumComponentLength,
int lpFileSystemFlags,
string lpFileSystemNameBuffer,
int nFileSystemNameSize
);
public HardInfoClass()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//取机器名
public string GetHostName()
{
return System.Net.Dns.GetHostName();
}
//取CPU编号
public string GetCpuID()
{
try
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
string strCpuID = null ;
foreach( ManagementObject mo in moc )
{
strCpuID = mo.Properties["ProcessorId"].Value.ToString();
break;
}
return strCpuID;
}
catch
{
return "";
}
}//end method
//取第一块硬盘编号
public string GetHardDiskID()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
string strHardDiskID = null ;
foreach(ManagementObject mo in searcher.Get())
{
strHardDiskID = mo["SerialNumber"].ToString().Trim();
break;
}
return strHardDiskID ;
}
catch
{
return "";
}
}
//获取网卡MAC地址
public string GetNetCardMAC()
{
try
{
string stringMAC = "";
ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
}
}
return stringMAC;
}
catch
{
return "";
}
}
//获取硬盘信息的代码
public string GetVolOf(string drvID)
{
try
{
const int MAX_FILENAME_LEN = 256;
int retVal = 0;
int a =0;
int b =0;
string str1 = null;
string str2 = null;
int i = GetVolumeInformation(
drvID + @":/",
str1,
MAX_FILENAME_LEN,
ref retVal,
a,
b,
str2,
MAX_FILENAME_LEN
);
return retVal.ToString("x");
}
catch
{
return "";
}
}
//获取当前网卡IP地址
public string GetNetCardIP()
{
try
{
string stringIP = "";
ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
string[] IPAddresses = (string[]) MO["IPAddress"];
if(IPAddresses.Length > 0)
stringIP = IPAddresses[0].ToString();
}
}
return stringIP;
}
catch
{
return "";
}
}
}
}
==================
string stringMAC = "";
ManagementClass MC = new ManagementClass ("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
}
}
int mac1=stringMAC.IndexOf("MAC");
int mac2=stringMAC.IndexOf("mac");
if (!(mac1 >= 0 || mac2 >= 0))
{
trError.Visible = true;
lblError.Text = "**************!";
return;
}
- MAC获取绑订
- 绑定时获取到绑定项的索引
- MAC与IP解绑与绑定
- 获取当前绑定项的Index
- 子绑定控件获取父绑定项的值
- GridView绑定时通过RowDataBound事件获取数据源列值
- GridView绑定时通过RowDataBound事件获取数据源列值
- repeater绑定时获取HTML形式的控件
- 订餐系统——后台获取GridView值
- READ_TEXT获取 采购订单行项目-项目文本
- 获取MAC
- 获取MAC
- 获取Mac
- 获取mac
- mac 获取
- 解绑
- 解绑
- asp.net中子级Repeater获取父级Repeater绑定项的值 Eval
- 如何解决,对待在做项目中所遇到的问题?/?
- 用c#做了个播放器
- 项目管理实践【四】Bug跟踪管理【Bug Trace and Management】
- SQL优化-索引
- sql语句优化!
- MAC获取绑订
- 二维指针应用
- 爱生活,爱拉芳!
- 完美卸载.net framework 2.0
- Oracle语句优化30个规则详解
- 在同一个根目录下,给出一个〖参照路径〗,计算〖当前程序目录〗与〖参照路径〗的相对路径
- DPL,RPL,CPL 之间的联系和区别
- 项目经理的十大成功态度
- 组策略小范例1