Using system; use system.Runtime.InteropServices; Using System.Management; Namespace Hardware {///
// get CPU number 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 // take the first disk ID 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 "";}} // end public enum NCBCONST {NCBNAMSZ = 16, / * absolute length of a net name * / MAX_LANA = 254, / * lana's in range 0 to MAX_LANA inclusive * / NCBENUM = 0x37 , / * NCB ENUMERATE LANA NUMBERS * / NRC_GOODRET = 0x00, / * good return * / NCBRESET = 0x32, / * NCB RESET * / NCBASTAT = 0x33, / * NCB ADAPTER STATUS * / NUM_NAMEBUF = 30, / * Number of NAME's BUFFER * /} [StructLayout (LayoutKind.Sequential)] public struct ADAPTER_STATUS {[MarshalAs (UnmanagedType.ByValArray, SizeConst = 6)] public byte [] adapter_address; public byte rev_major; public byte reserved0; public byte adapter_type; public byte rev_minor;
public ushort duration; public ushort frmr_recv; public ushort frmr_xmit; public ushort iframe_recv_err; public ushort xmit_aborts; public uint xmit_success; public uint recv_success; public ushort iframe_xmit_err; public ushort recv_buff_unavail; public ushort t1_timeouts; public ushort ti_timeouts; public uint reserved1; public ushort free_ncbs; public ushort max_cfg_ncbs; public ushort max_ncbs; public ushort xmit_buf_unavail; public ushort max_dgram_size; public ushort pending_sess; public ushort max_cfg_sess; public ushort max_sess; public ushort max_sess_pkt_size; public ushort name_count;} [StructLayout (LayoutKind.Sequential)] public struct NAME_BUFFER {[Marshalas (unmanagedtype.byvalarray, sizeconst = (int) ncbconst.ncbnamsz)] public byte [] name; public byte name_num; public byte name_flags;} [structlayou t (LayoutKind.Sequential)] public struct NCB {public byte ncb_command; public byte ncb_retcode; public byte ncb_lsn; public byte ncb_num; public IntPtr ncb_buffer; public ushort ncb_length; [MarshalAs (UnmanagedType.ByValArray, SizeConst = (int) NCBCONST.NCBNAMSZ )] public byte [] ncb_callname; [MarshalAs (UnmanagedType.ByValArray, SizeConst = (int) NCBCONST.NCBNAMSZ)] public byte [] ncb_name; public byte ncb_rto; public byte ncb_sto; public IntPtr ncb_post; public byte ncb_lana_num; public byte ncb_cmd_cplt [Marshalas (unmanagedtype.byvalarray, sizeconst = 10)] public Byte [] NCB_RESERVE; public INTPTR NCB_EVENT
} [StructLayout (LayoutKind.Sequential)] public struct LANA_ENUM {public byte length; [MarshalAs (UnmanagedType.ByValArray, SizeConst = (int) NCBCONST.MAX_LANA)] public byte [] lana;} [StructLayout (LayoutKind.Auto)] public struct ASTAT {public ADAPTER_STATUS adapt; [MarshalAs (UnmanagedType.ByValArray, SizeConst = (int) NCBCONST.NUM_NAMEBUF)] public NAME_BUFFER [] NameBuff;} public class Win32API {[DllImport ( "NETAPI32.DLL")] public static extern char Netbios (Ref NCB NCB); PUBLIC STRING GETMACADDRESS () {string addr = ""; try {int CB; ASTAT Adapter; NCB NCB = New NCB (); char uretcode; lana_enum lenum; ncb.ncb_command = (byte) ncbconst. NCBENUM; cb = Marshal.SizeOf (typeof (LANA_ENUM)); Ncb.ncb_buffer = Marshal.AllocHGlobal (cb); Ncb.ncb_length = (ushort) cb; uRetCode = Win32API.Netbios (ref Ncb); lenum = (LANA_ENUM) Marshal .Ptrtostructure (ncb.ncb_buffer, typeof (lanta_enum)); Marshal.Freehg Lobal (ncb.ncb_buffer; if (uretcode! = (short) ncbconst.nrc_goodret) return ""; for (int i = 0; i