Next available drive letter - mpr.dll

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to programmatically find the next available drive letter that
could be used to map a file share? Or is my best bet to just call net use
and parse the output?



Thanks in advanced.



-Jon
 
Jon,

Why not just call GetLogicalDrives through the P/Invoke layer. This
will give you the currently available disk drives. You then take the
letters which aren't in that set to figure out which drive letters are
available, and you can then order them and take the first as your drive
letter.
 
Yep, that will work. I just couldn't readily find it. Thanks.

-Jon

Nicholas Paldino said:
Jon,

Why not just call GetLogicalDrives through the P/Invoke layer. This
will give you the currently available disk drives. You then take the
letters which aren't in that set to figure out which drive letters are
available, and you can then order them and take the first as your drive
letter.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Is it possible to programmatically find the next available drive letter
that could be used to map a file share? Or is my best bet to just call
net use and parse the output?



Thanks in advanced.



-Jon
 
Nicholas said:
Why not just call GetLogicalDrives through the P/Invoke layer. This
will give you the currently available disk drives. You then take the
letters which aren't in that set to figure out which drive letters are
available, and you can then order them and take the first as your drive
letter.

Calling DriveInfo.GetDrives() of using WMI to get all the used
drives and then find the first not used may not be so elegant,
but I would still consider it a nicer way of doing it.

Arne
 
<Jon Meyer> wrote in messageWhy not just call GetLogicalDrives through the P/Invoke layer

Because that will only return local drives - what if there are other
mapped network drives?
 
Back
Top