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
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.
Frank Rizzo said:Note thein the comment.