Unmounting a USB Pen-Drive via code

Asked

Viewed 476 times

7

I wonder how I can do to disassemble a removable drive(Pen-Drive) via c code#.

  • If you go to a Unix-based system with Mono, it should be the easiest thing in the world, just a Shell command. With Mono or . NET for Windows, I believe that it should be necessary to use the Windows API, which is not so friendly. When I get home I’ll look for a solution, if by then no one has posted a.

  • I think that’s right @Renan, I’m trying to find some that works only it’s hard. Obg :)

  • Take a look at the source of this project: http://www.codeproject.com/Articles/13530/Eject-USB-disks-using-C

  • I was able to solve @Tiagocésaroliveira . Obg for the help.

3 answers

3


From Windows XP you can use the native command MOUNTVOL. According to your documentation:

Creates, Labels, or lists a volume mount point. Mountvol is a way to link volumes without requiring a drive Letter.

Translating:

Create, delete or list a mount point volume. Mountvol is a way to link volumes without the need for a drive letter.

Using its code as the basis, this would be the call without the need for any external component:

private static void EjectDrive(char driveLetter)
{
    ProcessStartInfo ps = new ProcessStartInfo("mountvol.exe", driveLetter + ": /d");
    Process.Start(ps);
}
  • 1

    Perfect! It worked exactly as expected! No need for external component. I tested it here on Windows 7 and it worked. Obg Onosendai :)

  • 1

    I’m glad it worked, @Rsouza!

2

  • This article had already taken a look. But it is mt complex, I ended up finding an easier solution :) Obg

2

So, you guys, let’s go I managed to find a program that does this.

http://www.uwe-sieber.de/drivetools_e.html

And I did it that way.

private static void EjectDrive(char driveLetter)
    {
        ProcessStartInfo ps = new ProcessStartInfo("RemoveDrive.exe", driveLetter + ":");
        Process.Start(ps);
    }

Along with this Removedrive at the root of the program. Obg Galera.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.