How To Detect Removable Drives (USB, SD) In ElectronJS/NodeJS

时间:2019-04-16 23:20:06

标签: node.js powershell electron

I'm using node-powershell to run a Powershell script every 5 seconds to retrieve the list of connected removable media drives for an ElectronJS desktop app with Angular front-end. It works...

 Get-WmiObject Win32_Volume -Filter "DriveType='2'"

Is there a way to do this without a constantly running setInterval, or to simply trigger an event when a USB device/SD card is plugged in or removed?

Goal: The app is intended for internal Windows users at my company. The UI shows tabs for each connected drive with drive letter and details, and adds or removes tabs accordingly. I'm trying to see if there's a "better" way of doing this more efficiently than the setInterval and Powershell script method that I currently have. While it works, it feels like there could be a better way that I'm not aware of. usb-detection doesn't really work for me since it's USB only and doesn't provide a drive letter.

0 个答案:

没有答案