1

is there a way to find out if a drive can be ejected and removed (since it is a drive connected via USB) programatically?

If yes: how can this be done?

SztupY
  • 10,291
  • 8
  • 64
  • 87
Elmi
  • 5,899
  • 15
  • 72
  • 143
  • 3
    To the people voting to close this question, isn't it implicit that he's asking how to do this programmatically? – tenfour Dec 08 '14 at 09:29
  • Do you wish to find out, whether a drive can technically be removed/ejected, or whether it is safe to do now? – IInspectable Dec 08 '14 at 09:33
  • 1
    This shouldn't have been flagged. The OP is just asking for a starting point. – hkBattousai Dec 08 '14 at 09:40
  • This is a valid question. It only requires a small clarification on the side of OP. – pmr Dec 08 '14 at 09:43
  • @tenfour you can vote to reopen. – Luchian Grigore Dec 08 '14 at 09:49
  • @Elmi If you want to eject the drive, what's stopping you from doing that? Why do you need to know ahead of time whether or not doing so will succeed? I think you should expand your question to make it a little more clear why you are asking. – David Heffernan Dec 08 '14 at 10:09
  • My question is tagged with WinAPI, C and C++ - so it should be clear I'm asking for a solution to check this out of a program and don't want to eject anythign manually. – Elmi Dec 08 '14 at 10:16
  • Do you want a solution in both C and C++? In my view there should be a single tag, namely `winapi`. – David Heffernan Dec 08 '14 at 10:34
  • The duplicate doesn't answer this question exactly. – SztupY Dec 08 '14 at 12:04

1 Answers1

-2

Based on this MSDN documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364939%28v=vs.85%29.aspx

GetDriveType [..] determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive.

SztupY
  • 10,291
  • 8
  • 64
  • 87
Jongware
  • 22,200
  • 8
  • 54
  • 100
  • 1
    I didn't downvote, but this only tells you if the drive is actually removable. It does not tell you if it is safe to actually remove the drive. Presuming that this is what OP wants to know, of course. – pmr Dec 08 '14 at 09:43
  • I downvoted, mine was the third one. This does not answer the question as asked. – David Heffernan Dec 08 '14 at 10:08
  • @David: but it *does* -- this API tells whether a drive is removable: "... can be ejected and removed". Can you expand on what you are reading in the question? – Jongware Dec 08 '14 at 10:18
  • 1
    I'm assuming that "can be ejected" means "is not busy working on locked files". – David Heffernan Dec 08 '14 at 10:34
  • Admittedly that is a valid interpretation. In that case, the duplicate doesn't answer it either as it *will* eject, rather than check *if* it can. ("Garfield, you can be very destructive." "I can?") – Jongware Dec 08 '14 at 10:47
  • That's what I think is the case too. However, I have to wonder if that's a time-of-check-vs-time-of-use (or in this case, -end-of-use) race condition... – andlabs Dec 08 '14 at 13:38