1

I have the output of a command

reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" 

which I need to:

1) Filter to include only TrueType fonts

2) Shorten down the output to only include the font's name (everything up to the "(TrueType)")

Is it possible to do this, and if so, how?

I've already tried using

reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" | 
findstr /I /C:"(TrueType)"

and got the output

Arial (TrueType)    REG_SZ    arial.ttf
Arial Black (TrueType)    REG_SZ    ariblk.ttf
Arial Bold (TrueType)    REG_SZ    arialbd.ttf
Arial Bold Italic (TrueType)    REG_SZ    arialbi.ttf
Arial Italic (TrueType)    REG_SZ    ariali.ttf
ect.

but from there I couldn't figure out how to omit the filenames and the "REG_SZ" text. I tried setting them all to variables with help from this post

SETLOCAL ENABLEDELAYEDEXPANSION
SET count=1
FOR /F "tokens=* USEBACKQ" %%F IN (`reg query 
"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" | 
findstr /I /C:"(TrueType)"`) DO (
  SET var!count!=%%F
  SET /a count=!count!+1
)
ECHO %var1%
ECHO %var2%
ECHO %var3%
ENDLOCAL

But again, this wouldn't work because each computer has a different amount of fonts, so there's no set amount of variables to assign. Also, the files for each font have different amounts of characters in the filename, so using

echo %var1:~,-X%

wouldn't work, nor would the opposite

echo %var1:~,X%

So ultimately, I'm back to square one with

reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" | 
findstr /I /C:"(TrueType)"

Is there any way to achieve the outcome I need?

2 Answers2

0

You can do it using a for loop and using the closing parenthesis as delimiter:

@echo off
setlocal enabledelayedexpansion
for /f "delims=)" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" ^| find /i "TrueType"') do (
   set "str=%%i)"
   echo !str:  =!
)

and if you do not want to use delayedexpansion

@echo off
for /f "delims=)" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" ^| find /i "TrueType"') do (
   set "str=%%i)"
   call echo %%str:  =%%
)
Gerhard
  • 22,678
  • 7
  • 27
  • 43
0

Here's one way of achieving your intended goal:

@(For /F Delims^=( %%# In ('^""%__AppDir__%reg.exe" Query^
 "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"^|^
 "%__AppDir__%find.exe" /I "(TrueType)"^|"%__AppDir__%sort.exe"^"'
)Do @For /F Tokens^=* %%$ In ("%%#")Do @Echo(%%$)&Pause

If you'd prefer the output in a text file, change &Pause to >"TTF.txt"

Compo
  • 36,585
  • 5
  • 27
  • 39