ejectDrive and ejectDriveSync
xiao edited this page Mar 10, 2023
·
5 revisions
eject a drive by the specific drive letter.
async:
fswin.ejectDrive(letter, method, callback);
sync:
var result = fswin.ejectDriveSync(letter, method);
-
letter
is a letter of the alphabet to determine which drive to eject. -
method
is an integer between 0 to 2 to determine which method to use.
- use
DeviceIoControl
. this method is simple and works good with cdrom.- use
CM_Request_Device_EjectW
orCM_Query_And_Remove_SubTreeW
. this method works good with usb flash drive.- use
HotPlugEjectDevice
fromHotPlug.dll
. this method works good with most media types but requires user interaction. andHotPlug.dll
only exists insystem32
folder which means it is not possible to use this method when you execute a 32bit node process in a 64bit windows.
-
callback
is a function to make callback with. it takes only one argumentresult
. -
result
is a boolean value to indicate whether the operation is succeeded.
var fswin = require('fswin');
var letter = 'e';
//sync
console.log(fswin.ejectDriveSync(letter, 1));
//async
fswin.ejectDrive(letter, 2, console.log);