【问题标题】:Serial number of the usb on windows Ce 6.0 in c#c#中windows Ce 6.0上usb的序列号
【发布时间】:2013-01-18 01:18:09
【问题描述】:

我需要获取连接到 Windows ce 6.0 设备的 USB 记忆棒的序列号。我试过KernelIoControl,我得到了window ce 6.0设备的序列号,但没有连接到它的usb。

    private static string GetDeviceID()
    {
        // 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 is not 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");
                }
            }
        }

当我将 USB 记忆棒连接到 windows ce 6 设备时,它显示了一个新的硬盘识别,我需要进入这个新设备注册的属性,控制我的 windows ce 6 上可用的 USB 端口设备。

【问题讨论】:

  • USB 设备没有序列号。您可以获得 FAT32 卷的序列号,但它被简单地修改,因此无法用作许可证验证。改为购买加密狗。

标签: c# windows-ce usbserial


【解决方案1】:

您可能正在寻找的是USB_DEVICE_DESCRIPTOR。在大窗口中,您将使用 SetupDiGetDeviceProperty 来获取此信息,但在 CE 中,此值仅对驱动程序可用。我认为没有一种通用的方法可以从 CE 中的驱动程序中获取此信息。不过,您的驱动程序可能包含一个特殊的 IOCTL_ 来获取该信息。联系您的 OEM。

【讨论】:

  • 那么台式电脑呢?如何从连接到电脑的 USB 中获取序列号?我怎样才能选择我想要的那个。获取连接的 USB 列表,并可以在它们之间进行选择。在 C# 中。如果你知道,你会救我的。
  • 正如我所说,在大型 Windows(台式 PC)中,您可以使用 SetupDiGetDeviceProperty。例如,请参阅:stackoverflow.com/questions/3438366/setupdigetdeviceproperty
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-29
  • 1970-01-01
相关资源
最近更新 更多