你用这个函数试试DeviceIoControl:IOCTL_STORAGE_CHECK_VERIFY The IOCTL_STORAGE_CHECK_VERIFY DeviceIoControl operation determines whether a device's media is accessible; for example, whether the media is in the device. BOOL DeviceIoControl( (HANDLE) hDevice, // handle to device of interest IOCTL_STORAGE_CHECK_VERIFY, // dwIoControlCode, control code of // operation to perform NULL, // lpInBuffer is not used; must be NULL 0, // nInBufferSize is not used; must be zero NULL, // lpOutBuffer is not used; must be NULL 0, // nOutBufferSize is not used; // must be zero (LPDWORD) lpBytesReturned, // pointer to variable to receive // output byte count (LPOVERLAPPED) lpOverlapped // pointer to OVERLAPPED structure // for asynchronous operation );
The IOCTL_STORAGE_CHECK_VERIFY DeviceIoControl operation determines whether a device's media is accessible; for example, whether the media is in the device. BOOL DeviceIoControl(
(HANDLE) hDevice, // handle to device of interest
IOCTL_STORAGE_CHECK_VERIFY, // dwIoControlCode, control code of
// operation to perform
NULL, // lpInBuffer is not used; must be NULL
0, // nInBufferSize is not used; must be zero
NULL, // lpOutBuffer is not used; must be NULL
0, // nOutBufferSize is not used;
// must be zero
(LPDWORD) lpBytesReturned, // pointer to variable to receive
// output byte count
(LPOVERLAPPED) lpOverlapped // pointer to OVERLAPPED structure
// for asynchronous operation
);
{
char DeviceName[MAX_PATH];
HANDLE hDevice;
DWORD cbBytesAct = 0;
bool fMediaExist = false; sprintf(DeviceName, "\\\\.\\%s", Drive); hDevice = CreateFile(
DeviceName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
NULL,
NULL); if (hDevice != INVALID_HANDLE_VALUE) {
if (DeviceIoControl(
hDevice,
IOCTL_DISK_CHECK_VERIFY,
NULL,
0,
NULL,
0,
&cbBytesAct,
NULL)) {
fMediaExist = true;
} CloseHandle(hDevice);
} return( fMediaExist );
}