"Safely Remove Hardware" USB Key?
-
Is there a way within C# and .NET Framework to duplicate the "Safely Remove Hardware" functionality. I am using a USB Flash drive on a Windows XP system. I want to be be able to ensure that the device is removed from the system without loss of data. So I would imagine that the would some driver uninstall or removal of the device from registry or other location. Does anyone know of code to achieve this? I am currently using code to raise an event when the USB Flash device is added or removed. Based on the following: http://www.experts-exchange.com/Programming/Programming\_Languages/Dot\_Net/VB\_DOT\_NET/Q\_21599899.html Just to clarify, I cannot use the standard "Safely Remove Hardare" function that appears in the status bar as My application will not boot to the standard windows shell - so there will be no status bar.
-
Is there a way within C# and .NET Framework to duplicate the "Safely Remove Hardware" functionality. I am using a USB Flash drive on a Windows XP system. I want to be be able to ensure that the device is removed from the system without loss of data. So I would imagine that the would some driver uninstall or removal of the device from registry or other location. Does anyone know of code to achieve this? I am currently using code to raise an event when the USB Flash device is added or removed. Based on the following: http://www.experts-exchange.com/Programming/Programming\_Languages/Dot\_Net/VB\_DOT\_NET/Q\_21599899.html Just to clarify, I cannot use the standard "Safely Remove Hardare" function that appears in the status bar as My application will not boot to the standard windows shell - so there will be no status bar.
You might be able to gleen something useful out of this[^]. It's a C++ app that will eject a device by
Drive letter: deveject -EjectDrive:E:
DeviceId: deveject "-EjectId:STORAGE\REMOVABLEMEDIA\7&20B2C23&0&RM"
Value Name: deveject "-EjectName:USB Mass Storage Device"If you're really adventurous, you could convert the code into a utility class in C#. Get ready for some serious P/Invoking! BTW: This is the ONLY code I've ever found that describes how to do this... And the comments are in German! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -- modified at 13:31 Thursday 9th February, 2006