Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eject USB drive

Status
Not open for further replies.

Dachyon

Programmer
Nov 4, 2002
32
NZ
Hi All,
I have been trying to find a way to eject a USB mass storage device from my system using C# (WinXP). I found a WinAPI called EjectDiskFromSADrive() in ntmsapi.dll ( however I am having trouble getting it to work.

In my code, I chose to call the Unicode implemetation :-
Code:
[DllImport("ntmsapi.dll", CharSet = CharSet.Unicode)]
        public static extern long EjectDiskFromSADriveW(
           [In, MarshalAs(UnmanagedType.LPWStr)] string lpComputerName,
           [In, MarshalAs(UnmanagedType.LPWStr)] string lpAppName,
           [In, MarshalAs(UnmanagedType.LPWStr)] string lpDeviceName,
           [In] int hWnd,
           [In, MarshalAs(UnmanagedType.LPWStr)] string lpTitle,
           [In, MarshalAs(UnmanagedType.LPWStr)] string lpMessage,
           [In] int dwOptions);

Method call :-

Code:
long val = EjectDiskFromSADriveW("", "", "\\\\.\\E", 0, "A Title", "A Message", 4);

Returns a value 8242573992334983171 - no idea what that could be...
Has anyone used this API before ?
Thanks in advance,
Dachyon.
 
That MSDN says that that function is Vista-only.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Don't you wish you were writing in linux? Then you could say "umount /dev/usb0" and you'd be done...

As for windows, WMI would be the way to go. You may also want to look into the ms ddk (Driver Development Kit) as it may provide some samples of working with USB Devices.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top