Programmatically Rendering Hardware Safe to Remove
Primary Software: LabVIEW Development Systems>>LabVIEW Full Development System
Primary Software Version: 7.1
Primary Software Fixed Version: N/A
Secondary Software: LabVIEW Run-Time Engine
Problem: How do I programmatically remove a USB device from my system without having to go through the Windows GUI to Safely Remove Hardware?
Solution: This can be done by calling an executable called DevEject. DevEject is a piece of freeware that ejects removable hardware in a script.
Download and unzip 0316-208.zip. When you copy DevEject.exe to a folder in your PATH, typing deveject /? returns:
Usage: deveject.exe -EjectDrive:|-EjectName:|-EjectId: [-v] [-Debug]
NOTE: The switches are case sensitive.
When you type deveject from a command prompt, the command lists the hardware it that is eject-able:
DevEject 1.0 2003 c't/Matthias Withopf
'Plug and Play Monitor' 'DISPLAY\_YV0003\4&5B20C67&0&00000400&00&02'
REMOVEABLE]
'Default Monitor' 'DISPLAY\DEFAULT_MONITOR\4&186BBD0C&0&80861000&00&22'
[REMOVEABLE]
'USB Mass Storage Device' 'USB\VID_413C&PID_9001\5&252D5D84&0&4'
[REMOVEABLE]
'1394 Net Adapter #2' 'V1394\NIC1394\EA86461324FC000'
[REMOVEABLE]
When you type
deveject -EjectName:"USB Mass Storage Device"
or
deveject -EjectId:"USB\VID_413C&PID_9001\5&252D5D84&0&4"
you will get:
Ejecting 'USB Mass Storage Device' [USB\VID_413C&PID_9001\5&252D5D84&0&4]...ok.
1 device(s) ejected.
The attached VI demonstrates how to use this exe with the System Exec VI in LabVIEW. Save the exe on the C drive (
C:\deveject.exe) before running the VI.
Related Links:
Attachments:
- 0316-208.zip
- Safely Remove Hardware.vi
Report Date: 02/23/2007
Last Updated: 06/16/2009
Document ID: 46M3PJPR