G
Guest
Hi,
how can I get a list of all "free" drive letters?
Thanks in advance, Randy
how can I get a list of all "free" drive letters?
Thanks in advance, Randy
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.

Nicholas Paldino said:Randy,
For this, I would call the GetLogicalDrives or GetLogicalDriveStrings
functions in the Win32 API through the P/Invoke layer. It will give you the
drive letters that are occupied. All you have to do is remove those from
the list of known letters (a-z) and you have your free drive letters.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Randy said:Hi,
how can I get a list of all "free" drive letters?
Thanks in advance, Randy
Randy said:Nicholas,
thanks a lot for your answer!!
Randy
Nicholas Paldino said:Randy,
For this, I would call the GetLogicalDrives or GetLogicalDriveStrings
functions in the Win32 API through the P/Invoke layer. It will give you
the
drive letters that are occupied. All you have to do is remove those from
the list of known letters (a-z) and you have your free drive letters.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Randy said:Hi,
how can I get a list of all "free" drive letters?
Thanks in advance, Randy

Jonathan Allen said:I would suggest this instead of PInvoke, if only because its managed code.
WqlObjectQuery objectQuery = new WqlObjectQuery("select * from
Win32_LogicalDisk");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);
ManagementObjectCollection disks = searcher.Get();
foreach (ManagementObject disk in disks)
{
Console.WriteLine("Disk = " + disk["deviceid"]);
}
--
Jonathan Allen
Randy said:Nicholas,
thanks a lot for your answer!!
Randy
Nicholas Paldino said:Randy,
For this, I would call the GetLogicalDrives or
GetLogicalDriveStrings
functions in the Win32 API through the P/Invoke layer. It will give you
the
drive letters that are occupied. All you have to do is remove those
from
the list of known letters (a-z) and you have your free drive letters.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Hi,
how can I get a list of all "free" drive letters?
Thanks in advance, Randy
Frank Rizzo said:Does
WqlObjectQuery objectQuery = new WqlObjectQuery("delete from
Win32_LogicalDisk where Drive='C'")
remove the drive?![]()
Willy said:There is no such thing like "Delete" in WQL, the syntax is SQL like but only
a subset is used.
in the comment.Frank Rizzo said:Note thein the comment.
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.