C# 开发智能设备 怎么获取本机(PDA) 的mac地址 用VS2008 C#开发的智能设备怎么 获取智能设备的mac地址,或者什么唯一标识都行,就是获取一个PDA的唯一标识,各位大虾 帮帮忙,还有就是PDA的系统是win ce 之前用的System.Management; 不好使,就不要说了,是能设备根本就掉不出来这个方法. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 手头没得测试环境,你自己试试行不行吧。先添加引用 OpenNetCF.Net string netinfo = ""; foreach (INetworkInterface item in NetworkInterface.GetAllNetworkInterfaces()) { netinfo += item.Name + "\r\n"; netinfo += item.CurrentIpAddress + "\r\n"; netinfo += item.GetPhysicalAddress() + "\r\n"; } MessageBox.Show(netinfo); 现在调出的都是网络的东西,我想调用一个pda中唯一标识,那个属性能实现? 你可以用windows api来取得设备id [DllImport("coredll.dll", EntryPoint = "KernelIoControl", SetLastError = true)] private extern static 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 IOCTL_HAL_GET_DEVICEID = ((FILE_DEVICE_HAL) << 16) | ((0x0) << 14) | ((21) << 2) | (0x0); public string GetPDASerialNumber() { byte[] outputBuffer = new byte[256]; Int32 outputBufferSize = outputBuffer.Length; Int32 bytesReturned = 0; 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 String.Empty; } Int32 presetIdOffset = BitConverter.ToInt32(outputBuffer, 4); Int32 platformIdOffset = BitConverter.ToInt32(outputBuffer, 0xc); Int32 platformIdSize = BitConverter.ToInt32(outputBuffer, 0x10); StringBuilder sb = new StringBuilder(); sb.Append(String.Format(CultureInfo.InvariantCulture, "{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))); for (int i = platformIdOffset; i < platformIdOffset + platformIdSize; i++) { sb.Append(String.Format(CultureInfo.InvariantCulture, "{0:X2}", outputBuffer[i])); } // return the device id string return sb.ToString(); } public static class DeviceInfo { [DllImport("coredll.dll")] private extern static int GetDeviceUniqueID([In, Out] byte[] appdata, int cbApplictionData, int dwDeviceIDVersion, [In, Out] byte[] deviceIDOuput, out uint pcbDeviceIDOutput); /// <summary> /// 获取设备ID /// </summary> /// <returns></returns> public static string GetDeviceId() { byte[] buffer = GetDeviceID("MyAppString"); StringBuilder sb = new StringBuilder(); for (int x = 0; x < buffer.Length; x++) { sb.Append(string.Format("{0:x2}", buffer[x])); } return sb.ToString().ToUpper(); } private static byte[] GetDeviceID(string AppString) { byte[] AppData = new byte[AppString.Length]; for (int count = 0; count < AppString.Length; count++) AppData[count] = (byte)AppString[count]; int appDataSize = AppData.Length; byte[] DeviceOutput = new byte[20]; uint SizeOut = 20; GetDeviceUniqueID(AppData, appDataSize, 1, DeviceOutput, out SizeOut); return DeviceOutput; } }我有个项目用的是段,也是在csdn.net上找的。。 coredll.dll里好像没有GetDeviceUniqueID这个接口,调用不了啊~ c# 网络编程 TCP/IP 服务器端 引用com组件后目录下生成的dll都得带上? Vc.net...事件注册 如何获得wav播放的当前位置 C#怎么在日期后面逐渐加一自动生成不同的编号? 日期变编号自动从001开始? ComboBox下拉列表不能显示 请问,网络广播和网络电视如何实现啊?(直播得,不要录播的) (急急急……)关于C#复制ACCESS数据库中的数据并保存到oracle数据库中 有关Datagrid 控件问题? SQL的存储过程问题,高手请~~~~~~~ strCmd = "****" 里面用变量。 如何对JPG图片进行有效性校验,判断是否是不是一副有效图片
foreach (INetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
{
netinfo += item.Name + "\r\n";
netinfo += item.CurrentIpAddress + "\r\n";
netinfo += item.GetPhysicalAddress() + "\r\n";
}
MessageBox.Show(netinfo);
[DllImport("coredll.dll", EntryPoint = "KernelIoControl", SetLastError = true)]
private extern static 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 IOCTL_HAL_GET_DEVICEID =
((FILE_DEVICE_HAL) << 16) | ((0x0) << 14)
| ((21) << 2) | (0x0);
public string GetPDASerialNumber()
{
byte[] outputBuffer = new byte[256];
Int32 outputBufferSize = outputBuffer.Length;
Int32 bytesReturned = 0; 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 String.Empty;
} Int32 presetIdOffset = BitConverter.ToInt32(outputBuffer, 4);
Int32 platformIdOffset = BitConverter.ToInt32(outputBuffer, 0xc);
Int32 platformIdSize = BitConverter.ToInt32(outputBuffer, 0x10); StringBuilder sb = new StringBuilder();
sb.Append(String.Format(CultureInfo.InvariantCulture, "{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))); for (int i = platformIdOffset; i < platformIdOffset + platformIdSize; i++)
{
sb.Append(String.Format(CultureInfo.InvariantCulture, "{0:X2}", outputBuffer[i]));
} // return the device id string
return sb.ToString();
}
public static class DeviceInfo
{
[DllImport("coredll.dll")]
private extern static int GetDeviceUniqueID([In, Out] byte[] appdata,
int cbApplictionData,
int dwDeviceIDVersion,
[In, Out] byte[] deviceIDOuput,
out uint pcbDeviceIDOutput);
/// <summary>
/// 获取设备ID
/// </summary>
/// <returns></returns>
public static string GetDeviceId()
{
byte[] buffer = GetDeviceID("MyAppString");
StringBuilder sb = new StringBuilder();
for (int x = 0; x < buffer.Length; x++)
{
sb.Append(string.Format("{0:x2}", buffer[x]));
}
return sb.ToString().ToUpper();
}
private static byte[] GetDeviceID(string AppString)
{
byte[] AppData = new byte[AppString.Length];
for (int count = 0; count < AppString.Length; count++)
AppData[count] = (byte)AppString[count];
int appDataSize = AppData.Length;
byte[] DeviceOutput = new byte[20];
uint SizeOut = 20;
GetDeviceUniqueID(AppData, appDataSize, 1, DeviceOutput, out SizeOut);
return DeviceOutput;
}
}
我有个项目用的是段,也是在csdn.net上找的。。
coredll.dll里好像没有GetDeviceUniqueID这个接口,调用不了啊~