wmic logicaldisk gives word output for drivetype instead of number (batch)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
LiveITA
Posts: 12
Joined: 25 Jan 2018 14:22

wmic logicaldisk gives word output for drivetype instead of number (batch)

#1 Post by LiveITA » 28 Jan 2018 08:26

I need to do stuffs when a network disk is found. To do so i need to look for drivetype 4 using this batch. The problem is that on my computer the drivetype for the network disk is "rete" (that means network in italian). How can i force wmic to output the number instead of the word?

Code: Select all

    for /F "usebackq tokens=1,2,3,4 " %%i in (`wmic logicaldisk get caption^,description^,drivetype 2^>NUL`) do (
    if %%l equ 4 ( 
    stuff I make him do goes here
    )
    )  
Oddly it works well with drivetype 2, which means removable drive.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: wmic logicaldisk gives word output for drivetype instead of number (batch)

#2 Post by aGerman » 28 Jan 2018 12:06

I assume it's rather an issue of the number of tokens. Just run

Code: Select all

wmic logicaldisk get caption,description,drivetype
in a CMD window. One or more adjacent spaces separate the tokens.

Run

Code: Select all

wmic logicaldisk get caption,description,drivetype /format:csv
This and setting the delimiter to a comma in your FOR /F loop may solve the problem.

Steffen

LiveITA
Posts: 12
Joined: 25 Jan 2018 14:22

Re: wmic logicaldisk gives word output for drivetype instead of number (batch)

#3 Post by LiveITA » 28 Jan 2018 13:30

I'm not really good with batch, if i set delim=, after tokens it does not work. What can i do?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: wmic logicaldisk gives word output for drivetype instead of number (batch)

#4 Post by aGerman » 28 Jan 2018 14:12

It would have been good to know if the tests in the CMD prompt worked for you. Now I can only guess.

Code: Select all

@echo off &setlocal
for /f "skip=2 delims=" %%i in (
  '2^>nul wmic logicaldisk get caption^,description^,drivetype /format:csv'
) do for /f "tokens=2-4 delims=," %%j in ("%%i") do (
  if %%l==4 (
    echo Caption     %%j
    echo Description %%k
    echo ~~~~~~~~~~
  )
)
pause
Steffen

LiveITA
Posts: 12
Joined: 25 Jan 2018 14:22

Re: wmic logicaldisk gives word output for drivetype instead of number (batch)

#5 Post by LiveITA » 28 Jan 2018 15:06

Oh sorry
anyway it works perfectly, thanks :)

LiveITA
Posts: 12
Joined: 25 Jan 2018 14:22

Re: wmic logicaldisk gives word output for drivetype instead of number (batch)

#6 Post by LiveITA » 28 Jan 2018 15:50

Jusr wondering, will it work on an account without admin privileges?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: wmic logicaldisk gives word output for drivetype instead of number (batch)

#7 Post by aGerman » 28 Jan 2018 17:36

Your WMIC command will work regardless if it was run elevated or not. But a network drive is always mapped for a specific user account. That means that another account on the same computer (e.g. the SYSTEM account) will not see the drives mapped for your account.

Steffen

Post Reply