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. USB ejection

USB ejection

Scheduled Pinned Locked Moved C#
adobewindows-admin
3 Posts 3 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.
  • P Offline
    P Offline
    Pyro Joe
    wrote on last edited by
    #1

    You know in Windows xp or 2000, there is still the possibility of loosing data if you just yank out your flash drive, but to do it the proper way, you must go through a series of annoying dialogs. If I have the user enter their drive letter, for which the letter would be stored in the registry or something, Is there something I can access in Windows to programatically eject the drive without having to go through all those dialogs. For instance, simply run the app from the desktop with an invisible form that would exit once it had ejected (successfully) your drive. This would be very helpful to me, thanks!!!

    D J 2 Replies Last reply
    0
    • P Pyro Joe

      You know in Windows xp or 2000, there is still the possibility of loosing data if you just yank out your flash drive, but to do it the proper way, you must go through a series of annoying dialogs. If I have the user enter their drive letter, for which the letter would be stored in the registry or something, Is there something I can access in Windows to programatically eject the drive without having to go through all those dialogs. For instance, simply run the app from the desktop with an invisible form that would exit once it had ejected (successfully) your drive. This would be very helpful to me, thanks!!!

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

      There's nothing in the .NET FCL that will do this. You'll have to use the Win32 API DeviceIoCtl functions to get at the USB bus, enumerate it, find the device your looking for, then build the appropriate IOCTL message and send it to the Device Manager. There is very little information around to do this, so you'll have to do a bunch of your own research. A Managed C++ .DLL might help you out alot in this situation, saving you from P/Invoking the Device Management functions and structures. Google for "USB C# DeviceIoControl" and you should come up with at least a few tidbits to get you started. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      1 Reply Last reply
      0
      • P Pyro Joe

        You know in Windows xp or 2000, there is still the possibility of loosing data if you just yank out your flash drive, but to do it the proper way, you must go through a series of annoying dialogs. If I have the user enter their drive letter, for which the letter would be stored in the registry or something, Is there something I can access in Windows to programatically eject the drive without having to go through all those dialogs. For instance, simply run the app from the desktop with an invisible form that would exit once it had ejected (successfully) your drive. This would be very helpful to me, thanks!!!

        J Offline
        J Offline
        Joel Lucsy
        wrote on last edited by
        #3

        Dialogs? Have you tried left-clicking the "safely remove hardware" icon in the system tray, which will popup a menu, and pick the device to unload? It should be that simple. -- Joel Lucsy

        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