2013-01-16 54 views
0

我需要獲得連接到Windows CE 6.0設備的USB棒的序列號。我嘗試了KernelIoControl,我得到了window ce 6.0設備的序列號,但沒有連接到它的usb。在Windows 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設備,它讓我看到一個新的硬盤承認,我需要來註冊這個新設備的性能,得到上可用的USB端口的控制我的Windows CE 6設備。

+1

USB設備沒有序列號。您可以獲得FAT32卷的序列號,但它被輕微修改,因此無法用作許可證驗證。改爲購買加密狗。 –

回答

0

你可能要找的是USB_DEVICE_DESCRIPTOR。在大窗口中,您將使用SetupDiGetDeviceProperty獲取此信息,但在CE中,此值僅適用於驅動程序。我不認爲在CE中有一種通用的方式來從驅動程序獲取這些信息。不過,您的驅動程序可能包含一個特殊的IOCTL_來獲取該信息。聯繫您的OEM。

+0

和dektop pc呢?我怎麼能從連接到電腦的USB的序列號?我如何選擇我想要的。獲取usb列表,並可以在它們之間進行選擇。在C#中。如果你知道的話,你會救我的。 – user1788654

+0

正如我所說,在大Windows(臺式PC)中,您可以使用SetupDiGetDeviceProperty。有關示例,請參閱:http://stackoverflow.com/questions/3438366/setupdigetdeviceproperty – PaulH

相關問題