Last active
March 25, 2024 14:14
-
-
Save heldr/3494570 to your computer and use it in GitHub Desktop.
add windows fonts by command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM http://www.msfn.org/board/topic/119612-how-to-install-a-font-via-the-command-line/ | |
@ECHO OFF | |
TITLE Adding Fonts.. | |
REM Filename: ADD_Fonts.cmd | |
REM Script to ADD TrueType and OpenType Fonts for Windows | |
REM By Islam Adel | |
REM 2012-01-16 | |
REM How to use: | |
REM Place the batch file inside the folder of the font files OR: | |
REM Optional Add source folder as parameter with ending backslash and dont use quotes, spaces are allowed | |
REM example "ADD_fonts.cmd" C:\Folder 1\Folder 2\ | |
IF NOT "%*"=="" SET SRC=%* | |
ECHO. | |
ECHO Adding Fonts.. | |
ECHO. | |
FOR /F %%i in ('dir /b "%SRC%*.*tf"') DO CALL :FONT %%i | |
REM OPTIONAL REBOOT | |
REM shutdown -r -f -t 10 -c "Reboot required for Fonts installation" | |
ECHO. | |
ECHO Done! | |
PAUSE | |
EXIT /b 0 | |
:FONT | |
ECHO. | |
REM ECHO FILE=%~f1 | |
SET FFILE=%~n1%~x1 | |
SET FNAME=%~n1 | |
SET FNAME=%FNAME:-= % | |
IF "%~x1"==".otf" SET FTYPE=(OpenType) | |
IF "%~x1"==".ttf" SET FTYPE=(TrueType) | |
ECHO FILE=%FFILE% | |
ECHO NAME=%FNAME% | |
ECHO TYPE=%FTYPE% | |
COPY /Y "%SRC%%~n1%~x1" "%SystemRoot%\Fonts\" | |
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "%FNAME% %FTYPE%" /t REG_SZ /d "%FFILE%" /f | |
GOTO :EOF |
I spent a lot of time to find a way for installing font without restart. Finally I found this ClickFont. It's an easy and exact solution :)
Link: http://www.softpedia.com/get/Others/Font-Utils/Clickfont.shtml
in line 25 please use exit /b 0 instead of just exit, as this will avoid closing the cmd window, giving you a chance to review the output
updated! Thanks! 🍵
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great script! The only problem is that it doesn't work for font files with spaces in them. I have altered line 19 to fix it.
FOR /F "tokens=" %%i in ('dir /b "%SRC%.*tf"') DO CALL :FONT "%%i"
Seems to work well. Still doesn't work with characters such as "&" but I've just renamed those files as a workaround.