[Carol Buchmiller - MSFT] Please post questions to the MSDN Forums at http://forums.microsoft.com/msdn. You will likely get a quicker response through the forum than through the Community Content.
I try to use this but come out with an error code (50) which means The request is not supported.
Why? I am using VC++ 6.0
------------below is my code------
#include <windows.h>
#include <WinIoCtl.h>
#include <stdio.h>
BOOL GetUsbInfo(MEDIA_SERIAL_NUMBER_DATA *pmty)
{
HANDLE hDevice; // handle to the drive to be examined
BOOL bResult; // results flag
DWORD junk; // discard results
hDevice = CreateFile(TEXT("\\\\.\\F:"), // drive
0, // no access to the drive
FILE_SHARE_READ | // share mode
FILE_SHARE_WRITE,
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // do not copy file attributes
if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
{
return (FALSE);
}
bResult = DeviceIoControl(hDevice, // device to be queried
IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER, // operation to perform
NULL, 0, // no input buffer
pmty, sizeof(*pmty), // output buffer
&junk, // # bytes returned
(LPOVERLAPPED) NULL); // synchronous I/O
CloseHandle(hDevice);
return (bResult);
}
int main(int argc, char *argv[])
{
MEDIA_SERIAL_NUMBER_DATA pmty;
BOOL bResult; // generic results flag
bResult = GetUsbInfo(&pmty);
if ( bResult)
{
printf("NumLength = %ld\n", pmty.SerialNumberLength);
}
else
{
printf ("GetUsbInfo failed. Error %ld.\n", GetLastError ());
}
return ((int)bResult);
}