Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- :: This script generates a list of installed fonts and writes it to a file with
- :: a name derived from the current date and time and a user-supplied tag. The
- :: script counts the fonts, and displays the resulting number. The script
- :: compares the generated list with the most recent older list; if no
- :: differences are encountered, or if the user did not supply a tag, the
- :: generated file is deleted.
- setlocal enableextensions disabledelayedexpansion
- set "BASENAME=FontList"
- set "PATTERN=%BASENAME% ??????-???? *.txt"
- set "KEYNAME=HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts"
- set "TIMETAG="
- for /f "usebackq delims=" %%t in (
- `wmic os get localdatetime ^| find "."`
- ) do if not defined TIMETAG set "TIMETAG=%%~t"
- set "TIMETAG=%TIMETAG:~2,6%-%TIMETAG:~8,4%"
- set "PREVFILE="
- if exist "%PATTERN%" for /f "usebackq delims=" %%f in (
- `dir /b /o:-d "%PATTERN%" ^| find /i ".txt"`
- ) do if not defined PREVFILE set "PREVFILE=%%~f"
- set "FILETAG="
- :argloop
- if "%~1" == "" goto :argdone
- if defined FILETAG set "FILETAG=%FILETAG% "
- set "FILETAG=%FILETAG%%~1"
- shift /1
- goto :argloop
- :argdone
- set "DELETEFILE="
- if not defined FILETAG set "DELETEFILE=1"
- if not defined FILETAG set "FILETAG=Temp"
- set "FILETAG=%FILETAG:~0,18%"
- :trailingspaceloop
- if not "%FILETAG:~-1%" == " " goto :trailingspacedone
- set "FILETAG=%FILETAG:~0,-1%"
- goto :trailingspaceloop
- :trailingspacedone
- set "FILENAME=%BASENAME% %TIMETAG% %FILETAG%.txt"
- if not exist "%FILENAME%" goto :usefilename
- echo Cannot use file name "%FILENAME%": file exists.
- exit /b 1
- :usefilename
- set "FONTCOUNT=0"
- for /f "usebackq delims=" %%f in (
- `reg query "%KEYNAME%" ^| find " REG_SZ " ^| sort /locale C`
- ) do call :fontentry "%%~f"
- if "%FONTCOUNT%" == "1" (
- echo Found 1 font
- ) else (
- echo Found %FONTCOUNT% fonts
- )
- if not defined PREVFILE (
- echo.
- goto :comparedone
- )
- fc "%PREVFILE%" "%FILENAME%" > nul 2> nul
- if not errorlevel 1 (
- echo The font list has not been changed
- echo.
- set "DELETEFILE=1"
- goto :comparedone
- )
- echo The font list has been changed
- echo .
- fc "%PREVFILE%" "%FILENAME%"
- :comparedone
- dir /o:d "%PATTERN%" 2> nul | find /i ".txt"
- if defined DELETEFILE del "%FILENAME%" > nul 2> nul
- exit /b
- :: ----------------------------------------------------------------------------
- :: call :fontentry "value"
- :: ----------------------------------------------------------------------------
- :: The subroutine :fontentry is called with one argument, which is a quoted
- :: string representing a registry entry extracted from %KEYNAME%, in the format
- :: returned by reg query. The subroutine will increase %FONTCOUNT% and write
- :: the entry to %FILENAME%. Leading spaces are deleted, REG_SZ and the
- :: surrounding spaces are replaced with " = ", multiple spaces are replaced
- :: with one space, and some problematic characters are sanitized.
- :fontentry
- set "FONTENTRY=%~1"
- set "FONTENTRY=%FONTENTRY:~4%"
- :shrinkspacesloop
- set "FONTENTRYTEMP=%FONTENTRY: = %"
- if "%FONTENTRYTEMP%" == "%FONTENTRY%" goto :shrinkspacesdone
- set "FONTENTRY=%FONTENTRYTEMP%"
- goto :shrinkspacesloop
- :shrinkspacesdone
- set "FONTENTRY=%FONTENTRY: REG_SZ = = %"
- set "FONTENTRY=%FONTENTRY:&=+%"
- set "FONTENTRY=%FONTENTRY:^=\%"
- set "FONTENTRY=%FONTENTRY:>=(%"
- set "FONTENTRY=%FONTENTRY:<=)%"
- set "FONTENTRY=%!!|!%"
- set /a "FONTCOUNT+=1"
- >> "%FILENAME%" echo %FONTENTRY%
- exit /b
- :: ----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement