Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am a Novice but recently had a problem of running a batch file on the 'n' number of usb disk attached leaving the local disks. If anybody can help in
a batch script file to find the number of disk attached to the system , run the batch file in n number of disk. run the batch file on all the removable disks and exits.

Thanks in anticipation
Posted
Updated 29-Feb-12 21:21pm
v2

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900