Next available drive letter - mpr.dll

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
G

Guest

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
 
A

Arne Vajhøj

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
 
P

Peter Forman

<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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top