@echo off
cls
setlocal enabledelayedexpansion
set "_DRIVE.LETTERS.FREE=Z Y X W V U T S R Q P O N M L K J I H G F E D C B A "
for /f "skip=1 tokens=1,2 delims=: " %%a in ('wmic logicaldisk get deviceid^,volumename') do (
set "_DRIVE.LETTERS.USED=!_DRIVE.LETTERS.USED!%%a,%%b@"
set "_DRIVE.LETTERS.FREE=!_DRIVE.LETTERS.FREE:%%a =!"
)
set _DRIVE.LETTERS.USED=%_DRIVE.LETTERS.USED:~0,-2%
set _DRIVE.LETTERS.USED=%_DRIVE.LETTERS.USED:,@=, @%
set _DRIVE.LETTERS
Fast, flexible and efficient. Although a little complex.
If anyone is lucky enough to be using Vista (Vista Ultimate SP2 b6002, in my case) and the gwmi and wmic snippets given here don't work exactly, here is what I did to make it work.
For gwmi, if you receive no output, try changing the DriveType to 3. If still having problems, remove the -filter option altogether and analyze output.
gwmi win32_LogicalDisk -filter DriveType=3
For wmic, if you receive "Invalid GET Expression", then try putting the get expression in quotes:
wmic logicaldisk get "caption,providername,drivetype,volumename"
This will get most of it:
If you have any drives mapped via subst you would also need to get those:
For completeness, you would do it like this in Powershell (if you are on windows 7 or have installed it):
You can also do it from the command prompt or a batch file using WMI like this:
To use diskpart, there is no need to create an intermediate file. Try:
Fast, flexible and efficient. Although a little complex.
inspired by Scott
also shows CD drive letters and network mounted disk letters. No need to have admin rights.
sample output
If anyone is lucky enough to be using Vista (Vista Ultimate SP2 b6002, in my case) and the gwmi and wmic snippets given here don't work exactly, here is what I did to make it work.
For gwmi, if you receive no output, try changing the DriveType to 3. If still having problems, remove the -filter option altogether and analyze output.
For wmic, if you receive "Invalid GET Expression", then try putting the get expression in quotes:
This site has a much simpler set of calls:
http://en.code-bude.net/2013/02/23/show-all-drives-in-command-prompt/
Show local drives:
wmic logicaldisk get deviceid, volumename, description
If you want to show only drives of a particular type, the wmic command can be further expanded to include a where clause.
wmic logicaldisk where drivetype=2 get deviceid, volumename, description
Types
0 => Unknown
1 => No Root Directory
2 => Removable Disk
3 => Local Disk
4 => Network Drive
5 => Compact Disc
6 => RAM Disk
I found the diskpart approach reports DVD drives with no disc inserted, and doesn't report SD cards with valid drive volumes