Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. "Safely Remove Hardware" USB Key?

"Safely Remove Hardware" USB Key?

Scheduled Pinned Locked Moved C#
csharphtmldotnetcomadobe
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LiamD
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • L LiamD

      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.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups