NetRock6
asked on
Batch File- Finding Drive Description
Hi ...
I have to install few programs (like: abc.exe, EFC.exe...etc) that are located in the folder ...\MonitorSetup\.
The installation method is different depending, If these programs are in USB drive or Localdrive.
I was wondering, if someone can help to create a batch file to automate the above task.
I can get the drive letter and check for the programs using below code, but I do not know how to get the description also to match to the drive letter. Once, I know the matching description, the batch file can goto the USB section or LocalDrive to install the programs accordingly.
Thank You For Your Help.
I have to install few programs (like: abc.exe, EFC.exe...etc) that are located in the folder ...\MonitorSetup\.
The installation method is different depending, If these programs are in USB drive or Localdrive.
I was wondering, if someone can help to create a batch file to automate the above task.
I can get the drive letter and check for the programs using below code, but I do not know how to get the description also to match to the drive letter. Once, I know the matching description, the batch file can goto the USB section or LocalDrive to install the programs accordingly.
Thank You For Your Help.
@echo off
setlocal enabledelayedexpansion
for /f %%d in ('wmic logicaldisk get caption') do (
if exist "%%d\MonitorSetup\abc.exe" (
do set drvlet=%%d
echo "!drvlet!\MonitorSetup\"
)
)
ASKER
What I am trying to figure out is: how to find the right "description" after knowing the "caption".
Thank you for your help.
Thank you for your help.
I guess depends on what is 'right' description for you?
I didn't include the Description field in my WMIC example because it didn't seem 'descriptive' enough.
My example here has a usb drive connected on G:
I didn't include the Description field in my WMIC example because it didn't seem 'descriptive' enough.
My example here has a usb drive connected on G:
Caption Description VolumeName
C: Local Fixed Disk Host01
D: CD-ROM Disc
E: Local Fixed Disk External01
F: Network Connection Share01
G: Local Fixed Disk TOSHIBA EXT
ASKER
For the USB Flash Drive the Description is "Removable disk".
The USB drives that are fat32 usb devices 32GB storage or greater, the Description appears as "Local Fixed Disk".
The USB drives that are fat32 usb devices 8GB storage appears as "Removable disk".
I am looking to match the found 'caption' with "Removable disk" (For USB Drive) OR
"Local Fixed Disk" (For Local Partition).
Thanks.
The USB drives that are fat32 usb devices 32GB storage or greater, the Description appears as "Local Fixed Disk".
The USB drives that are fat32 usb devices 8GB storage appears as "Removable disk".
I am looking to match the found 'caption' with "Removable disk" (For USB Drive) OR
"Local Fixed Disk" (For Local Partition).
Thanks.
Try this and see if DriveType is a better attribute to base logic on. Unfortunately I don't have a FAT32 formatted USB drive >= 32GB to test with...
Also not that the output from WMIC is best processed though two FOR statements since WMIC terminates output lines with a carriage return rather than a carriage return line feed sequence, so this cleans that up.
Also not that the output from WMIC is best processed though two FOR statements since WMIC terminates output lines with a carriage return rather than a carriage return line feed sequence, so this cleans that up.
@echo off
setlocal EnableDelayedExpansion
rem Drive types from WMIC LogicalDisk:
rem 0 = Unknown
rem 1 = No Root Directory
rem 2 = Removable Disk
rem 3 = Local Disk
rem 4 = Network Drive
rem 5 = Compact Disc
rem 6 = RAM Disk
rem Search all disks looking for installation files, get drive letter and drive type
for /f "skip=2 tokens=*" %%A in ('wmic /output:stdout LogicalDisk get Caption^,DriveType /format:csv') do (
for /f "tokens=2,3 delims=," %%a in ("%%A") do (
if exist "%%a\MonitorSetup\abc.exe" do (
set drvlet=%%a
set drvtyp=%%b
echo "!drvlet!\MonitorSetup\","!drvtyp!"
)
)
)
rem Proceed depending on drive type
if %drvtyp% EQU 2 (
rem Treat as USB drive
) else (
rem Treat as fixed drive
)
~bp
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent Bill, THANK YOU so MUCH for your help.
After running your code, (the last comment), getting: 'do is not recognized as an internal....' error.
but do not know which one is causing this...
Thank You Again.
After running your code, (the last comment), getting: 'do is not recognized as an internal....' error.
but do not know which one is causing this...
Thank You Again.
Sorry, you had an extra do that was harmless, and I accidentally moved it to a harmful place. Change this line:
if exist "%%a\MonitorSetup\abc.exe" do (
to:
if exist "%%a\MonitorSetup\abc.exe" (
~bp
if exist "%%a\MonitorSetup\abc.exe"
to:
if exist "%%a\MonitorSetup\abc.exe"
~bp
This is what I get with this code:
(I have hard drive C, network share Z, and kingston USB in D, you are looking for drive types 3 and 2)
OUTPUT:
C:\Temp>x
drvltr is C: DriveType is 3
"C:\MonitorSetup\"
drvltr is D: DriveType is 2
drvltr is Z: DriveType is 4
(I have hard drive C, network share Z, and kingston USB in D, you are looking for drive types 3 and 2)
- @echo off
- setlocal enabledelayedexpansion
- for /f "tokens=1,2 delims=:" %%d in ('wmic logicaldisk get caption^,DriveType ^|findstr :') do (
- set drvlet=%%d:
- set drvtyp=%%e
- for /f "tokens=* delims= " %%a in ("!drvtyp!") do set drvtyp=%%a
- echo drvltr is !drvlet! DriveType is !drvtyp!
- REM if exist "%%d\temp\dummy.txt" (
- if exist "!drvlet!\temp\dummy.txt" (
- echo "!drvlet!\MonitorSetup\" %drvtyp%
- )
- )
OUTPUT:
C:\Temp>x
drvltr is C: DriveType is 3
"C:\MonitorSetup\"
drvltr is D: DriveType is 2
drvltr is Z: DriveType is 4
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank YOU "arana" for your time and improvement.
Keep the Good JOB!
Keep the Good JOB!
Open in new window
To see everything WMIC can show, run this to send the results to file drives.txt. Then review the file drives.txt.
Open in new window