Windows 10
Hello,
I've got a Sandisk Cruzer inserted in a USB hub.
With the code included I can eject & unmount the stick.
It does'nt show in Windows after I run the code, so I'm guessing it works.
However if I eject through Windows the USB stick ready light goes out, but
not with my code, its ejected but the ready light stays on.
Is there a way to turn the ready light off?
Regards
Code:
if (EjectVolume((TCHAR)data[0]))
{
QMessageBox::information(this, tr("OK"),
("USB device '" + dl + "' ejected.\n\n"));
ui->info->clear();
}
Code:
BOOL EjectVolume(TCHAR cDriveLetter)
{
HANDLE hVolume;
BOOL fRemoveSafely = FALSE;
BOOL fAutoEject = FALSE;
// Open the volume.
hVolume = OpenVolume(cDriveLetter);
if (hVolume == INVALID_HANDLE_VALUE)
return FALSE;
// Lock and dismount the volume.
if (LockVolume(hVolume) && DismountVolume(hVolume)) {
fRemoveSafely = TRUE;
// Set prevent removal to false and eject the volume.
if (PreventRemovalOfVolume(hVolume, FALSE) &&
AutoEjectVolume(hVolume))
fAutoEject = TRUE;
}
// Close the volume so other processes can use the drive.
if (!CloseVolume(hVolume))
return FALSE;
//qDebug() << fRemoveSafely << fAutoEject;
if (fAutoEject)
printf("Media in Drive %c has been ejected safely.\n",
cDriveLetter);
if (fRemoveSafely)
printf("Media in Drive %c can be safely removed.\n",
cDriveLetter);
return TRUE;
}
Code:
Output:-
Media in Drive J has been ejected safely.
Media in Drive J can be safely removed.