{"id":828,"date":"2008-05-30T10:16:22","date_gmt":"2008-05-30T10:16:22","guid":{"rendered":"http:\/\/6teen.ru\/?p=691"},"modified":"2008-05-30T10:16:22","modified_gmt":"2008-05-30T10:16:22","slug":"6143","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=828","title":{"rendered":"\u0421\u0435\u0440\u0438\u0439\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 USB \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430"},"content":{"rendered":"<p>\u0421\u0435\u0440\u0438\u0439\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 USB \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>\u0421\u0435\u0440\u0438\u0439\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 USB \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\n\nuses JwaWinIoctl;\n\n\nprocedure GetSerial:String;\n  var Dummy   :DWord;\n      FHandle   :Cardinal;\n      RealPath  :String;\n      dg             :CHANGER_PRODUCT_DATA; \/\/falscher Datentyp? Laut SDK musste es eigentlich\n\/\/ MEDIA_SERIAL_NUMBER_DATA sein aber den gibs nicht\n      Serial        :String;\n      i                :byte;\nbegin\n        RealPath:='\\\\.\\F:';\n        FHandle:=CreateFile(PChar(RealPath),GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);\n        if DeviceIOControl(FHandle,IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER, nil, 0, @dg, sizeof(dg), dummy, nil) then begin\n            Serial:='';\n            for i:=0 to 31 do Serial:=Serial+IntToStr(dg.SerialNumber[i]);\n            Result:=Serial;\n          end;\n      end;\n    end;\n    Inc(pDrive, 4);\n  end;\nend;\n\n***************************************************************\n\nMEDIA_SERIAL_NUMBER_DATA Structure\n\nContains the serial number of a USB device. It is used by the IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER control code.\ntypedef struct _MEDIA_SERIAL_NUMBER_DATA {\n  ULONG SerialNumberLength;\n  ULONG Result;\n  ULONG Reserved[2];\n  UCHAR SerialNumberData[];\n} MEDIA_SERIAL_NUMBER_DATA,\n *PMEDIA_SERIAL_NUMBER_DATA;\nMembers\nSerialNumberLength\n\nThe size of the SerialNumberData string, in bytes.\nResult\n\nThe status of the request.\nReserved\n\nReserved.\nSerialNumberData\n\nThe serial number of the device.\nRemarks\n\nNo header file is available for the MEDIA_SERIAL_NUMBER_DATA structure. Include the structure definition at the top of this page in your source code.\nRequirementsClient\tRequires Windows Vista or Windows XP.\n\n***********************************************************************\n\nIOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER Control Code\n\nRetrieves the serial number of a USB device.\n\nTo perform this operation, call the DeviceIoControl function with the following parameters.\nBOOL DeviceIoControl(\n  (HANDLE) hDevice,                      \/\/ handle to device\n  IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER, \/\/ dwIoControlCode\n  NULL,                                  \/\/ lpInBuffer\n  0,                                     \/\/ nInBufferSize\n  (LPVOID) lpOutBuffer,                  \/\/ output buffer\n  (DWORD) nOutBufferSize,                \/\/ size of output buffer\n  (LPDWORD) lpBytesReturned,             \/\/ number of bytes returned\n  (LPOVERLAPPED) lpOverlapped            \/\/ OVERLAPPED structure\n);\nParameters\nhDevice\n\nA handle to the device. To obtain a device handle, call the CreateFile function.\ndwIoControlCode\n\nThe control code for the operation. Use IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER for this operation.\nlpInBuffer\n\nNot used with this operation; set to NULL.\nnInBufferSize\n\nNot used with this operation; set to zero.\nlpOutBuffer\n\nA pointer to a MEDIA_SERIAL_NUMBER_DATA structure that receives the serial number.\nnOutBufferSize\n\nThe size of the output buffer, in bytes.\nlpBytesReturned\n\nA pointer to a variable that receives the size of the data stored in the output buffer, in bytes.\n\nIf the output buffer is too small, the call fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and lpBytesReturned is zero.\n\nIf lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation returns no output data and lpOutBuffer is NULL, DeviceIoControl makes use of lpBytesReturned. After such an operation, the value of lpBytesReturned is meaningless.\n\nIf lpOverlapped is not NULL, lpBytesReturned can be NULL. If this parameter is not NULL and the operation returns data, lpBytesReturned is meaningless until the overlapped operation has completed. To retrieve the number of bytes returned, call GetOverlappedResult. If hDevice is associated with an I\/O completion port, you can retrieve the number of bytes returned by calling GetQueuedCompletionStatus.\nlpOverlapped\n\nA pointer to an OVERLAPPED structure.\n\nIf hDevice was opened without specifying FILE_FLAG_OVERLAPPED, lpOverlapped is ignored.\n\nIf hDevice was opened with the FILE_FLAG_OVERLAPPED flag, the operation is performed as an overlapped (asynchronous) operation. In this case, lpOverlapped must point to a valid OVERLAPPED structure that contains a handle to an event object. Otherwise, the function fails in unpredictable ways.\n\nFor overlapped operations, DeviceIoControl returns immediately, and the event object is signaled when the operation has been completed. Otherwise, the function does not return until the operation has been completed or an error occurs.\nReturn Value\n\nIf the operation completes successfully, DeviceIoControl returns a nonzero value.\n\nIf the operation fails or is pending, DeviceIoControl returns zero. To get extended error information, call GetLastError.\nRequirementsClient\tRequires Windows Vista or Windows XP.\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u0435\u0440\u0438\u0439\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 USB \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[433,451],"tags":[594,1486,1713,1819],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/828"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=828"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/828\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=828"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}