获取PPC设备的ID号
2008-10-06 11:34
260 查看
[DllImport("coredll.dll")]
private static extern bool KernelIoControl(Int32 IoControlCode, IntPtr
InputBuffer, Int32 InputBufferSize, byte[] OutputBuffer, Int32
OutputBufferSize, ref Int32 BytesReturned);
private static Int32 FILE_DEVICE_HAL = 0x00000101;
private static Int32 FILE_ANY_ACCESS = 0x0;
private static Int32 METHOD_BUFFERED = 0x0;
private static Int32 IOCTL_HAL_GET_DEVICEID =
((FILE_DEVICE_HAL) << 16) | ((FILE_ANY_ACCESS) << 14)
| ((21) << 2) | (METHOD_BUFFERED);
private static string GetDeviceID()
{
byte[] OutputBuffer = new byte[256];
Int32 OutputBufferSize, BytesReturned;
OutputBufferSize = OutputBuffer.Length;
BytesReturned = 0;
// Call KernelIoControl passing the previously defined
// IOCTL_HAL_GET_DEVICEID parameter
// We don?’t need to pass any input buffers to this call
// so InputBuffer and InputBufferSize are set to their null
// values
bool retVal = KernelIoControl(IOCTL_HAL_GET_DEVICEID,
IntPtr.Zero,
0,
OutputBuffer,
OutputBufferSize,
ref BytesReturned);
// If the request failed, exit the method now
if (retVal == false)
{
return null;
}
// Examine the OutputBuffer byte array to find the start of the
// Preset ID and Platform ID, as well as the size of the
// PlatformID.
// PresetIDOffset -The number of bytes the preset ID is offset
// from the beginning of the structure
// PlatformIDOffset - The number of bytes the platform ID is
// offset from the beginning of the structure
// PlatformIDSize - The number of bytes used to store the
// platform ID
// Use BitConverter.ToInt32() to convert from byte[] to int
Int32 PresetIDOffset = BitConverter.ToInt32(OutputBuffer, 4);
Int32 PlatformIDOffset = BitConverter.ToInt32(OutputBuffer, 0xc);
Int32 PlatformIDSize = BitConverter.ToInt32(OutputBuffer, 0x10);
// Convert the Preset ID segments into a string so they can be
// displayed easily.
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(String.Format("{0:X8}-{1:X4}-{2:X4}-{3:X4}-",
BitConverter.ToInt32(OutputBuffer, PresetIDOffset),
BitConverter.ToInt16(OutputBuffer, PresetIDOffset + 4),
BitConverter.ToInt16(OutputBuffer, PresetIDOffset + 6),
BitConverter.ToInt16(OutputBuffer, PresetIDOffset + 8)));
// Break the Platform ID down into 2-digit hexadecimal numbers
// and append them to the Preset ID. This will result in a
// string-formatted Device ID
for (int i = PlatformIDOffset;
i < PlatformIDOffset + PlatformIDSize;
i++)
{
sb.Append(String.Format("{0:X2}", OutputBuffer[i]));
}
// return the Device ID string
return sb.ToString();
}
private static extern bool KernelIoControl(Int32 IoControlCode, IntPtr
InputBuffer, Int32 InputBufferSize, byte[] OutputBuffer, Int32
OutputBufferSize, ref Int32 BytesReturned);
private static Int32 FILE_DEVICE_HAL = 0x00000101;
private static Int32 FILE_ANY_ACCESS = 0x0;
private static Int32 METHOD_BUFFERED = 0x0;
private static Int32 IOCTL_HAL_GET_DEVICEID =
((FILE_DEVICE_HAL) << 16) | ((FILE_ANY_ACCESS) << 14)
| ((21) << 2) | (METHOD_BUFFERED);
private static string GetDeviceID()
{
byte[] OutputBuffer = new byte[256];
Int32 OutputBufferSize, BytesReturned;
OutputBufferSize = OutputBuffer.Length;
BytesReturned = 0;
// Call KernelIoControl passing the previously defined
// IOCTL_HAL_GET_DEVICEID parameter
// We don?’t need to pass any input buffers to this call
// so InputBuffer and InputBufferSize are set to their null
// values
bool retVal = KernelIoControl(IOCTL_HAL_GET_DEVICEID,
IntPtr.Zero,
0,
OutputBuffer,
OutputBufferSize,
ref BytesReturned);
// If the request failed, exit the method now
if (retVal == false)
{
return null;
}
// Examine the OutputBuffer byte array to find the start of the
// Preset ID and Platform ID, as well as the size of the
// PlatformID.
// PresetIDOffset -The number of bytes the preset ID is offset
// from the beginning of the structure
// PlatformIDOffset - The number of bytes the platform ID is
// offset from the beginning of the structure
// PlatformIDSize - The number of bytes used to store the
// platform ID
// Use BitConverter.ToInt32() to convert from byte[] to int
Int32 PresetIDOffset = BitConverter.ToInt32(OutputBuffer, 4);
Int32 PlatformIDOffset = BitConverter.ToInt32(OutputBuffer, 0xc);
Int32 PlatformIDSize = BitConverter.ToInt32(OutputBuffer, 0x10);
// Convert the Preset ID segments into a string so they can be
// displayed easily.
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(String.Format("{0:X8}-{1:X4}-{2:X4}-{3:X4}-",
BitConverter.ToInt32(OutputBuffer, PresetIDOffset),
BitConverter.ToInt16(OutputBuffer, PresetIDOffset + 4),
BitConverter.ToInt16(OutputBuffer, PresetIDOffset + 6),
BitConverter.ToInt16(OutputBuffer, PresetIDOffset + 8)));
// Break the Platform ID down into 2-digit hexadecimal numbers
// and append them to the Preset ID. This will result in a
// string-formatted Device ID
for (int i = PlatformIDOffset;
i < PlatformIDOffset + PlatformIDSize;
i++)
{
sb.Append(String.Format("{0:X2}", OutputBuffer[i]));
}
// return the Device ID string
return sb.ToString();
}
相关文章推荐
- 获取PPC设备的ID号
- 获取手机设备ID
- 如何获取设备ID
- Android 能够获取到唯一的设备 ID 吗?
- 安卓获取渠道名渠道id Android获取设备唯一标识的终极解决方法,防止安卓7.0时崩溃问题
- android-获取设备id
- UWP 应用获取各类系统、用户信息 (2) - 商店授权信息、零售演示模式信息、广告 ID、EAS 设备信息、硬件识别信息、移动网络信息
- 获取ios设备的开发id
- android 获取设备Id
- Appium自动获取 Android 设备 id 和包名等信息(python)
- Android能够获取到唯一的设备ID吗?
- 如何获取Android移动终端设备唯一ID
- Android 获取设备ID
- 获取设备 ID 和名称
- Windows Phone 8获取设备ID
- iOS获取当前设备ID、版本号、build号
- Android获取设备ID、型号及其它信息
- 根据mac地址+deviceid获取设备唯一编码 获取手机及SIM卡相关信息
- 获取设备ID
- android系统获取系统相关信息(如Android设备的唯一ID等)(源码)