Read Cpu Id

read cpu id
None.gif using  System;
None.gif
using  System.Runtime.InteropServices;
None.gif
using  System.Management;
None.gif
namespace  Hardware
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary>
InBlock.gif
/// Hardware_Mac 的摘要说明。
ExpandedSubBlockEnd.gif
/// </summary>

InBlock.gifpublic class HardwareInfo
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
//取机器名 
InBlock.gif
public string GetHostName()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
return System.Net.Dns.GetHostName(); 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
InBlock.gif
//取CPU编号
InBlock.gif
public String GetCpuID() 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
try
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifManagementClass mc 
= new ManagementClass("Win32_Processor");
InBlock.gifManagementObjectCollection moc 
= mc.GetInstances();
InBlock.gif
InBlock.gifString strCpuID 
= null ;
InBlock.gif
foreach( ManagementObject mo in moc ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifstrCpuID 
= mo.Properties["ProcessorId"].Value.ToString();
InBlock.gif
break
ExpandedSubBlockEnd.gif}

InBlock.gif
return strCpuID;
ExpandedSubBlockEnd.gif}

InBlock.gif
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
return "";
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockEnd.gif}
//end method
InBlock.gif
InBlock.gif
//取第一块硬盘编号
InBlock.gif
public String GetHardDiskID() 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
try
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifManagementObjectSearcher searcher 
= new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
InBlock.gifString strHardDiskID 
= null ;
InBlock.gif
foreach(ManagementObject mo in searcher.Get()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifstrHardDiskID 
= mo["SerialNumber"].ToString().Trim();
InBlock.gif
break
ExpandedSubBlockEnd.gif}

InBlock.gif
return strHardDiskID ;
ExpandedSubBlockEnd.gif}

InBlock.gif
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
return "";
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}
//end 
InBlock.gif

InBlock.gif
public enum NCBCONST 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gifNCBNAMSZ 
=16/**//* absolute length of a net name */ 
ExpandedSubBlockStart.gifContractedSubBlock.gifMAX_LANA 
=254/**//* lana's in range 0 to MAX_LANA inclusive */ 
ExpandedSubBlockStart.gifContractedSubBlock.gifNCBENUM 
=0x37/**//* NCB ENUMERATE LANA NUMBERS */ 
ExpandedSubBlockStart.gifContractedSubBlock.gifNRC_GOODRET 
=0x00/**//* good return */ 
ExpandedSubBlockStart.gifContractedSubBlock.gifNCBRESET 
=0x32/**//* NCB RESET */ 
ExpandedSubBlockStart.gifContractedSubBlock.gifNCBASTAT 
=0x33/**//* NCB ADAPTER STATUS */ 
ExpandedSubBlockStart.gifContractedSubBlock.gifNUM_NAMEBUF 
=30/**//* Number of NAME's BUFFER */ 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Sequential)] 
InBlock.gif
public struct ADAPTER_STATUS 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=6)] 
InBlock.gif
public byte[] adapter_address; 
InBlock.gif
public byte rev_major; 
InBlock.gif
public byte reserved0; 
InBlock.gif
public byte adapter_type; 
InBlock.gif
public byte rev_minor; 
InBlock.gif
public ushort duration; 
InBlock.gif
public ushort frmr_recv; 
InBlock.gif
public ushort frmr_xmit; 
InBlock.gif
public ushort iframe_recv_err; 
InBlock.gif
public ushort xmit_aborts; 
InBlock.gif
public uint xmit_success; 
InBlock.gif
public uint recv_success; 
InBlock.gif
public ushort iframe_xmit_err; 
InBlock.gif
public ushort recv_buff_unavail; 
InBlock.gif
public ushort t1_timeouts; 
InBlock.gif
public ushort ti_timeouts; 
InBlock.gif
public uint reserved1; 
InBlock.gif
public ushort free_ncbs; 
InBlock.gif
public ushort max_cfg_ncbs; 
InBlock.gif
public ushort max_ncbs; 
InBlock.gif
public ushort xmit_buf_unavail; 
InBlock.gif
public ushort max_dgram_size; 
InBlock.gif
public ushort pending_sess; 
InBlock.gif
public ushort max_cfg_sess; 
InBlock.gif
public ushort max_sess; 
InBlock.gif
public ushort max_sess_pkt_size; 
InBlock.gif
public ushort name_count; 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Sequential)] 
InBlock.gif
public struct NAME_BUFFER 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)NCBCONST.NCBNAMSZ)] 
InBlock.gif
public byte[] name; 
InBlock.gif
public byte name_num; 
InBlock.gif
public byte name_flags; 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Sequential)] 
InBlock.gif
public struct NCB 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
public byte ncb_command; 
InBlock.gif
public byte ncb_retcode; 
InBlock.gif
public byte ncb_lsn; 
InBlock.gif
public byte ncb_num; 
InBlock.gif
public IntPtr ncb_buffer; 
InBlock.gif
public ushort ncb_length; 
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)NCBCONST.NCBNAMSZ)] 
InBlock.gif
public byte[] ncb_callname; 
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)NCBCONST.NCBNAMSZ)] 
InBlock.gif
public byte[] ncb_name; 
InBlock.gif
public byte ncb_rto; 
InBlock.gif
public byte ncb_sto; 
InBlock.gif
public IntPtr ncb_post; 
InBlock.gif
public byte ncb_lana_num; 
InBlock.gif
public byte ncb_cmd_cplt; 
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=10)] 
InBlock.gif
public byte[] ncb_reserve; 
InBlock.gif
public IntPtr ncb_event; 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Sequential)] 
InBlock.gif
public struct LANA_ENUM 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
public byte length; 
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)NCBCONST.MAX_LANA)] 
InBlock.gif
public byte[] lana; 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
InBlock.gif[StructLayout(LayoutKind.Auto)] 
InBlock.gif
public struct ASTAT 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
public ADAPTER_STATUS adapt; 
InBlock.gif[MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)NCBCONST.NUM_NAMEBUF)] 
InBlock.gif
public NAME_BUFFER[] NameBuff; 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
public class Win32API 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif[DllImport(
"NETAPI32.DLL")] 
InBlock.gif
public static extern char Netbios(ref NCB ncb); 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
InBlock.gif
public string GetMacAddress() 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
string addr=""
InBlock.gif
try
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
int cb; 
InBlock.gifASTAT adapter; 
InBlock.gifNCB Ncb
=new NCB(); 
InBlock.gif
char uRetCode; 
InBlock.gifLANA_ENUM lenum; 
InBlock.gif
InBlock.gifNcb.ncb_command 
= (byte)NCBCONST.NCBENUM; 
InBlock.gifcb 
= Marshal.SizeOf(typeof(LANA_ENUM)); 
InBlock.gifNcb.ncb_buffer 
= Marshal.AllocHGlobal(cb); 
InBlock.gifNcb.ncb_length 
= (ushort)cb; 
InBlock.gifuRetCode 
= Win32API.Netbios(ref Ncb); 
InBlock.giflenum 
= (LANA_ENUM)Marshal.PtrToStructure(Ncb.ncb_buffer, typeof(LANA_ENUM)); 
InBlock.gifMarshal.FreeHGlobal(Ncb.ncb_buffer); 
InBlock.gif
if(uRetCode != (short)NCBCONST.NRC_GOODRET) 
InBlock.gif
return ""
InBlock.gif
InBlock.gif
for(int i=0; i < lenum.length ;i++
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifNcb.ncb_command 
= (byte)NCBCONST.NCBRESET; 
InBlock.gifNcb.ncb_lana_num 
= lenum.lana[i]; 
InBlock.gifuRetCode 
= Win32API.Netbios(ref Ncb); 
InBlock.gif
if(uRetCode != (short)NCBCONST.NRC_GOODRET) 
InBlock.gif
return ""
InBlock.gif
InBlock.gifNcb.ncb_command 
= (byte)NCBCONST.NCBASTAT; 
InBlock.gifNcb.ncb_lana_num 
= lenum.lana[i]; 
InBlock.gifNcb.ncb_callname[
0]=(byte)'*'
InBlock.gifcb 
= Marshal.SizeOf(typeof(ADAPTER_STATUS)) + Marshal.SizeOf(typeof(NAME_BUFFER))*(int)NCBCONST.NUM_NAMEBUF; 
InBlock.gifNcb.ncb_buffer 
= Marshal.AllocHGlobal(cb); 
InBlock.gifNcb.ncb_length 
= (ushort)cb; 
InBlock.gifuRetCode 
= Win32API.Netbios(ref Ncb); 
InBlock.gifadapter.adapt 
= (ADAPTER_STATUS)Marshal.PtrToStructure(Ncb.ncb_buffer, typeof(ADAPTER_STATUS)); 
InBlock.gifMarshal.FreeHGlobal(Ncb.ncb_buffer); 
InBlock.gif
InBlock.gif
if (uRetCode == (short)NCBCONST.NRC_GOODRET) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
if(i>0
InBlock.gifaddr 
+= ":"
InBlock.gifaddr 
= string.Format("{0,2:X}{1,2:X}{2,2:X}{3,2:X}{4,2:X}{5,2:X}"
InBlock.gifadapter.adapt.adapter_address[
0], 
InBlock.gifadapter.adapt.adapter_address[
1], 
InBlock.gifadapter.adapt.adapter_address[
2], 
InBlock.gifadapter.adapt.adapter_address[
3], 
InBlock.gifadapter.adapt.adapter_address[
4], 
InBlock.gifadapter.adapt.adapter_address[
5]); 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif}

InBlock.gif
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{}
InBlock.gif
return addr.Replace(' ''0'); 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值