How do I get a list of drive letters and their associated labels on a windows system through a bat file?
|
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:
|
|||||||||||||
|
Fast, flexible and efficient. Although a little complex. |
|||||||
|
|
inspired by Scott
also shows CD drive letter. no need to be admin. |
||||
|
|
|
To use diskpart, there is no need to create an intermediate file. Try:
|
|||
|
|
|
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:
|
|||
|
|
|
@echo off echo list volume > scriptdiskpart diskpart/s scriptdiskpart del scriptdiskpart pause |
|||
|
sample output
|
|||
|
|
|
Somewhat kludgy, but works from a batch file:
|
|||
|
|
I found the diskpart approach reports DVD drives with no disc inserted, and doesn't report SD cards with valid drive volumes |
||||
|
|
|
Although it has enough answer, I'd like to add one when you want to use it in batch file. If you get "Invalid GET Expression", you could put a ^ before the ',', like below:
|
|||
|
|||
|
|
|
|||||||||||
|