c# wince 取设备号
来源:互联网 发布:鹏业软件官方价格 编辑:程序博客网 时间:2024/06/06 19:31
wince设备,有时为了做软件保护,采取注册限制,需要取设备的序列号,以下为通用的取法,网上抄的。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; using System.Diagnostics; using System.Runtime.InteropServices; using System.IO; using System.Security.Cryptography;namespace Check{ class LiangDeviceID { private static string[] strEncrypt = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP" }; private static Int32 METHOD_BUFFERED = 0; private static Int32 FILE_ANY_ACCESS = 0; private static Int32 FILE_DEVICE_HAL = 0x00000101; private const Int32 ERROR_NOT_SUPPORTED = 0x32; private const Int32 ERROR_INSUFFICIENT_BUFFER = 0x7A; private static Int32 IOCTL_HAL_GET_DEVICEID = ((FILE_DEVICE_HAL) << 16) | ((FILE_ANY_ACCESS) << 14) | ((21) << 2) | (METHOD_BUFFERED); [DllImport( "coredll.dll", SetLastError = true)] private static extern bool KernelIoControl(Int32 dwIoControlCode, IntPtr lpInBuf, Int32 nInBufSize, byte[] lpOutBuf, Int32 nOutBufSize, ref Int32 lpBytesReturned); public static string GetDeviceID() { try { // Initialize the output buffer to the size of a Win32 DEVICE_ID structure byte[] outbuff = new byte[20]; Int32 dwOutBytes; bool done = false; Int32 nBuffSize = outbuff.Length; // Set DEVICEID.dwSize to size of buffer. Some platforms look at // this field rather than the nOutBufSize param of KernelIoControl // when determining if the buffer is large enough. // BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0); dwOutBytes = 0; // Loop until the device ID is retrieved or an error occurs while (!done) { if (KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0, outbuff, nBuffSize, ref dwOutBytes)) { done = true; } else { int error = Marshal.GetLastWin32Error(); switch (error) { case ERROR_NOT_SUPPORTED: throw new NotSupportedException("IOCTL_HAL_GET_DEVICEID is not supported on this device ", new Win32Exception(error)); case ERROR_INSUFFICIENT_BUFFER: // The buffer wasn 't big enough for the data. The // required size is in the first 4 bytes of the output // buffer (DEVICE_ID.dwSize). nBuffSize = BitConverter.ToInt32(outbuff, 0); outbuff = new byte[nBuffSize]; // Set DEVICEID.dwSize to size of buffer. Some // platforms look at this field rather than the // nOutBufSize param of KernelIoControl when // determining if the buffer is large enough. // BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0); break; default: throw new Win32Exception(error, "Unexpected error "); } } } Int32 dwPresetIDOffset = BitConverter.ToInt32(outbuff, 0x4); // DEVICE_ID.dwPresetIDOffset Int32 dwPresetIDSize = BitConverter.ToInt32(outbuff, 0x8); // DEVICE_ID.dwPresetSize Int32 dwPlatformIDOffset = BitConverter.ToInt32(outbuff, 0xc); // DEVICE_ID.dwPlatformIDOffset Int32 dwPlatformIDSize = BitConverter.ToInt32(outbuff, 0x10); // DEVICE_ID.dwPlatformIDBytes StringBuilder sb = new StringBuilder(); for (int i = dwPresetIDOffset; i < dwPresetIDOffset + dwPresetIDSize; i++) { //sb.Append(String.Format( "{0:X2} ", outbuff[i])); sb.Append(String.Format("{0} ", outbuff[i])); } //sb.Append("- "); //for (int i = dwPlatformIDOffset; i < dwPlatformIDOffset + dwPlatformIDSize; i++) //{ // //sb.Append(String.Format( "{0:X2} ", outbuff[i])); // sb.Append(String.Format("{0} ", outbuff[i])); //} return sb.ToString(); } catch (System.Exception e) { MessageBox.Show("取设备序列号异常"+e.Message ); StringBuilder sb = new StringBuilder(); sb.Append("austec 010-59713137"); return sb.ToString(); } } public static string GetEncrypt( string strDeviceID ) { int i, no; StringBuilder sb = new StringBuilder(); for (i = 0; i < strDeviceID.Length; i++) { try { no = int.Parse(strDeviceID[i].ToString()); } catch (System.Exception ex) { no =1; } if (no > strEncrypt.Length) no = no%strEncrypt.Length; sb.Append(String.Format( "{0}", strEncrypt[no]) ); } return sb.ToString(); } }}
- c# wince 取设备号
- c# wince 取设备号
- C# wince 蜂鸣器 发声 C#调用设备驱动函数
- C# wince 蜂鸣器 发声 C#调用设备驱动函数
- C#开发wince与设备连接后的文档传送
- C# 访问WINCE设备的内存类实现
- WinCE获取设备ID
- WinCE设备驱动程序分类
- EVC连接WinCE设备
- Wince 添加蓝牙设备
- WMDC连接Wince设备
- WinCE 6.0设备管理器
- WINCE 获取设备ID
- Wince 添加蓝牙设备
- WINCE获取设备ID
- wince设备上获取sd卡的id号
- 使用RAPI库操作移动手持设备WINCE——C#语言描述
- [WinCE]通过网卡连接调试WinCE设备
- 规则引擎教程--多维决策表
- DFS+BFS
- WCF Debug 调试
- Android.mk解析
- getrlimit和setrlimit 获得linux下面的进程可用资源
- c# wince 取设备号
- CareerCup-5.7
- 线程知识点总结01
- http协议,httplib使用
- 【汇编语言】
- Chat_9
- 霍纳法则
- .net compact cf wince 5.0 wince 6.0 静态变量 释放问题
- Javah生成JNI头文件