Basically, it all is done via WMI:
http://en.wikipedia.org/wiki/Windows_Management_Instrumentation[
^].
In PowerShell (highly recommended):
$drives = Get-WmiObject Win32_Volume | Where { $_.DriveType -eq 2 }
Here, drive type 2 means "removable drive"
In legacy batch:
@wmic logicaldisk get volumeName, description, deviceId
Add some code to count them.
Please see:
http://technet.microsoft.com/en-us/library/bb742610.aspx[
^]
Good luck,
—SA