Maybe you can try with CM_Request_Device_Eject
(I have no SSD to test)
Eject SSD from c++ code
Hi
I'm attempting to remove an ejectable SSD from c++ code, but all examples I found are related on how to eject USD disks or CD rom. Not ssd.
Of course those examples works with usb but doesn't with SSD.
Up to now I can dismount and make it offline, but I can't eject. That is using DeviceIoControl I first open drive, lock it (FSCTL_LOCK_VOLUME), unmount
volume (FSCTL_DISMOUNT_VOLUME) and make offline (IOCTL_VOLUME_OFFLINE). It remains offline but its icon is still present and isn't removed.
Please can you suggest a place where I can find code or documentation regarding ?
Thanks
8 answers
Sort by: Oldest
-
Castorix31 81,736 Reputation points
2021-04-12T08:56:32.23+00:00 -
Francesco Cuzzocrea 1 Reputation point
2021-04-12T13:54:50.703+00:00 Thanks for the suggestion, but it doesn't work (VetoType returned tells that device isn't removable, but device is removable, I can remove it right clicking on the tray icon). CM_Request_Device_Eject works fine with usb disks (I use it for ejecting).
-
Castorix31 81,736 Reputation points
2021-04-12T15:09:22.597+00:00 Another test, x64 only because of HotPlug.dll =>
(change the DeviceInstanceId...)// #include <Cfgmgr32.h> typedef CONFIGRET(WINAPI* HPED)(HWND hWnd, PCWSTR DeviceInstanceId, DWORD dwFlags); HPED HotPlugEjectDevice = NULL; HMODULE hDLL = LoadLibrary(TEXT("HotPlug.dll")); if (hDLL != NULL) { HotPlugEjectDevice = (HPED)GetProcAddress(hDLL, "HotPlugEjectDevice"); if (HotPlugEjectDevice) { CONFIGRET cr = HotPlugEjectDevice(NULL, TEXT("USB\\VID_1058&PID_1001\\574341505734363536363133"), 0); // Test cr... } }
-
Francesco Cuzzocrea 1 Reputation point
2021-04-12T16:34:54.873+00:00 Thanks for the suggestion. Regarding previous suggestion, using API Monitor I see the call to CM_Request_Device_Eject_ExW when I eject an USB disk, but It isn't called when I eject an SSD. I have a lot of call, but I can't figure out which of these is related to ejecting. I will check HotPlugEjectDevice.
-
Francesco Cuzzocrea 1 Reputation point
2021-04-12T16:57:30.82+00:00 HI
I can't find any documentation regarding HotPlugEjectDevice. In case of SSD the text field shouldn't be usb, but what should I insert ? May be the ssd GUID that is TEXT("\?\Volume{<<GUID of SSD>>}") ?