-1

Several laptops now have two graphics cards and i need some help on how to add them to variables and output them onscreen or text file on a batch file.

On cmd i use wmic PATH Win32_videocontroller GET description and it outputs two graphics:

  • Description
NVIDIA GeForce MX150
Intel(R) UHD Graphics 620
  • But if I use:
for /F "tokens=2 delims='='" %%A in ('wmic PATH Win32_videocontroller GET description /value') do set vga=%%A
echo %vga%

I just get the Intel(R) UHD Graphics 620 and not both graphics!

I need all available graphics card, so I can output them onscreen and on a file using the variables:

  • Ex.
VGA1: NVIDIA GeForce MX150
VGA2: Intel(R) UHD Graphics 620

Thanks!

EDIT: I find a way to show both graphics, but I still don't know how to add them to separate variables :(

setlocal enabledelayedexpansion
set i=0
for /f "tokens=2 delims='='" %%a in ('wmic PATH Win32_videocontroller GET description /value ') do (
     set /a i+=1
     set VGA!i!=%%a
   )
set VGA

It shows both cards, although I would prefer:

VGA1: NVIDIA...  instead of  VGA1=NVIDIA... 

Replacing "=" by ": " but I also can't do it :(

VGA1=NVIDIA GeForce MX150
VGA2=Intel(R) UHD Graphics 620
Io-oI
  • 2,514
  • 3
  • 22
  • 29
Necro
  • 1
  • 2

3 Answers3

1

For this output:

VGA1: NVIDIA GeForce MX150
VGA2: Intel(R) UHD Graphics 620

Just try this:

@echo off  && setlocal enabledelayedexpansion

for /f tokens^=* %%a in ('
%__APPDIR__%wbem\wmic.exe PATH Win32_videocontroller GET description^|findstr [0-9]
')do echo/%%~a|find "NV" >nul && (set "_VGA1=VGA1: %%~a") || set "_VGA2=VGA2: %%~a" 
(for %%V in (vga1,vga2)do echo\!_%%~V!) && endlocal && "%__APPDIR__%timeout.exe" -1
Io-oI
  • 2,514
  • 3
  • 22
  • 29
1
@echo off
setlocal enabledelayedexpansion
set i=0
for /f "tokens=2 delims==" %%a in ('wmic PATH Win32_videocontroller GET description /value ') do (
  set /a i+=1
  set VGA!i!=%%a
)
rem set VGA
for /f "tokens=1,* delims==" %%A in ('set VGA') do echo %%A: %%B

set VGA prints name=value as that is what it does. Use a for /f loop to delimit on = and then just echo token1: token2

So you almost had it done. The '=' is a odd set of 3 delimiters though, use = instead.

I only have 1 card on the current machine, so output is:

VGA1: NVIDIA GeForce GTX 750 Ti

michael_heath
  • 5,262
  • 2
  • 12
  • 22
1

The output you are getting on the screen is the direct output from your set VGA command.

Without modifying the rest of your code you simply need to modify or replace that line.


You could replace it with:
For /F "Tokens=1*Delims==" %%G In ('Set VGA 2^>NUL')Do Echo %%G: %%H

Although for this particular method, you should really include a line before your to ensure that there weren't any existing variables with a name beginning with VGA before you ran the .

For /F "Delims==" %%G In ('Set VGA 2^>NUL')Do Set "%%G="


Alternatively, and simpler in this case, you could replace it with this instead:
If %i% Gtr 0 For /L %%G In (1,1,%i%)Do Echo VGA%%G: !VGA%%G!

If you didn't have delayed expansion enabled, there would be more overhead, (although negligible, as it's unlikely that you have more that two or three graphics cards in your system), you would change that to:

If %i% Gtr 0 For /L %%G In (1,1,%i%)Do Call Echo VGA%%G: %%VGA%%G%%


There is an issue, which may or may not be important to you whereby the descriptions could have trailing spaces. If you have this issue then you could consider changing your script to modify the output type from .

For example:

@Echo Off
SetLocal EnableDelayedExpansion
Set "i=0"
For /F Tokens^=6Delims^=^" %%G In (
  '"%__AppDir__%wbem\WMIC.exe" Path Win32_VideoController Get Description /Format:MOF 2^>NUL'
)Do Set /A i+=1&Set "VGA!i!=%%G"
If %i% Gtr 0 (For /L %%G In (1,1,%i%)Do Echo VGA%%G: !VGA%%G!)&Pause
Compo
  • 36,585
  • 5
  • 27
  • 39