Installing fonts via command line/script

jerrym

New member
Local time
6:31 AM
Messages
1
Location
Largo, Florida
Windows 7 has apparently changed the way fonts are installed. I have a web page that I use that when visiting the page it looks to see if a file called barcode.exe is installed in a particular folder and if it is not present it downloads the file and executes it. The exe file is designed to place 2 carolina bar code fonts into C:\windows\fonts. This works with no issues in both Windows XP and Windows Vista but is not working in Windows 7. I can manually install these into Windows 7 font folder with no problem, but need to be able to do it automatically. Does anyone know an effective command line to use to place a font into the font folder in Windows 7? Thanks...

Jerry Mill
 

My Computer

OS
Windows 7
in my my .bat file, I run Font.vbs file.

rem Add files

O:\BDARevit\Distra\Font.vbs

Text code inside of Font.vbs file as follows:

' Fonts.cfg
' January 13, 2010
' ----------------------------------------------------------
Option Explicit

Dim objShell, objFolder

Const FONTS = &H14&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FONTS)
objFolder.CopyHere "O:\BDARevit\Distra\architxt.ttf"

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FONTS)
objFolder.CopyHere "O:\BDARevit\Distra\BlankSerif.ttf"

Wscript.Quit
 

My Computer

OS
windows 7
Anyway to do this all within an existing batch file? Without launching a VB application?
 

My Computer

OS
Win7 and XP
This doesn't work for me in windows 7 professional from a windows server 2003.

It works like I have no permission to write in that folder (like if I run a batch file).

There is some non-standard option that I have to enable?

Thank you
 

My Computer

OS
windows 7 ultimate
When you install a font, all that you actually do is to copy the concerned .ttf file to the %systemroot%\fonts (in most cases that would simply be C:\windows\fonts) and add an entry in under the registry key
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts".

You can do this with a batch file as follows:

Rem fontinstall.bat
xcopy *.ttf %systemroot%\fonts
regedit /s font.reg

The font.reg would contain the following:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"fontname (TrueType)"="filename.ttf"

You would need to reboot to see the font.
 

My Computer

Computer Manufacturer/Model Number
Too many to describe...
OS
Windows 7 x64 pro/ Windows 7 x86 Pro/ XP SP3 x86
Not in windows 7!
You cannot access the font directory!
This is the problem!

Thanks anyway
 

My Computer

OS
windows 7 ultimate
Here's a batch file that should accomplish what you wish to achieve. Please note that, since you are accessing the HKLM branch of the registry, this MUST be run either from within an administrative account or from one that has been elevated to administrative privileges.

Code:
@ECHO OFF
XCOPY [COLOR=red]<Source>[/COLOR].[COLOR=red]<ext>[/COLOR] %systemroot%\fonts
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "[COLOR=red]<Fontname>[/COLOR] ([COLOR=red]<Type>[/COLOR])" /t REG_SZ /d "[COLOR=red]<Filename>[/COLOR].[COLOR=red]<ext>[/COLOR]" /f

You will need to provide the information in <red>.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dwarf Dwf/11/2012 r09/2013
OS
Windows 8.1 Pro RTM x64
CPU
Intel Core-i5-3570K 4-core @ 3.4GHz (Ivy Bridge) (OC 4.4GHz)
Motherboard
ASRock Z77 Extreme4-M
Memory
4 x 4GB DDR3-1600 Corsair Vengeance CMZ8GX3M2A1600C9B (16GB)
Graphics Card(s)
MSI GeForce GTX770 Gaming OC 2GB
Sound Card
Realtek High Definition on board solution (ALC 898)
Monitor(s) Displays
ViewSonic VA1912w Widescreen (VGA)
Screen Resolution
1440x900
Hard Drives
OCZ Agility 3 SSD 120GB SATA III x2 (RAID 0)
Samsung HD501LJ 500GB SATA II x2
Hitachi HDS721010CLA332 1TB SATA II
Iomega 1.5TB Ext USB 2.0
WD 2.0TB Ext USB 3.0
PSU
XFX Pro Series 850W Semi-Modular
Case
Gigabyte IF233
Cooling
1 x 120mm Front Inlet 1 x 120mm Rear Exhaust
Keyboard
Microsoft Comfort Curve Keyboard 3000 (USB)
Mouse
Microsoft Comfort Mouse 3000 for Business (USB)
Internet Speed
NetGear DG834Gv3 ADSL Modem/Router (Ethernet) ~4.0 Mb/s (O2)
Antivirus
Avast! 8.0.1497
Browser
IE 11
Other Info
Optical Drive: HL-DT-ST BD-RE BH10LS30 SATA Bluray
Lexmark S305 Printer/Scanner/Copier (USB)
WEI Score: 8.1/8.1/8.5/8.5/8.25
Asus Eee PC 1011PX Netbook (Windows 7 x86 Starter)
Thanks for the answers.

I put my frizquadratatt.ttf in the c:\ directory, then I create font.cmd

Code:
XCOPY c:\frizquadratatt.ttf %systemroot%\fonts
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Fritz Quadrata TT (True Type)" /t REG_SZ /d "frizquadratatt.ttf" /f

then I launch font.cmd from my desktop clicking "run as administrator"

it works fine...but I still haven't the font installed!!

ok, ok I have to restart the pc (WHY ?!?!? If you can doubleclick on a .ttf file, say install and you are immediatly able to use it!?!? ther must be another way!!) :mad:

Now I put this script in my logon.cmd in the domain server and tell the active directory to run it...but it doesn't work!! :cry:

Thank again
 

My Computer

OS
windows 7 ultimate
How to install a font via the command line? ADD_Fonts.cmd

Here is a batch script to install Fonts in any Folder automatically.
Paste the following code in notepad and save it as "ADD_Fonts.cmd"
place the cmd file inside the folder of the fonts you want to install and run it or
add the source folder as a parameter. for example "ADD_fonts.cmd" C:\Folder 1\Folder 2\

it will install all the fonts automatically by copying them to the Windows Fonts Folder and creating the required Registry values for them

Code:
@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

: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
 

My Computer

OS
Windows XP 32-bit
The best way to do this is to create a vbs script and run it from a command line. So open notepad and paste:
Code:
Const FONTS = &H14& 

 Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.Namespace(FONTS)
objFolder.CopyHere "C:\Scripts\Myfont.ttf"
Just change C:\Scripts\Myfont.ttff to the current location of ttf file you want to install and that's the only thing you should have to replace, go to file and save as and make sure you save it as a .vbs file. Then just save the vbs script where ever you like and run the script via cmd or batch file. If you need multiple fonts installed just repeat the objFolder.CopyHere "C:\Scripts\Myfont.ttf" line at the end with each font name in the appropriate place.

I should also mention that the batch file or command should look like this:
Code:
cscript "C:\folder\InstallFont.vbs"

I've tried the first few answers on this forum to no avail and this is the only thing that has worked for me so I thought I'd share.


reference: Hey, Scripting Guy! How Can I Install Fonts Using a Script? - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Ultimate x64
The best way to do this is to create a vbs script and run it from a command line. So open notepad and paste:
Code:
Const FONTS = &H14& 
 
 Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.Namespace(FONTS)
objFolder.CopyHere "C:\Scripts\Myfont.ttf"
Just change C:\Scripts\Myfont.ttff to the current location of ttf file you want to install and that's the only thing you should have to replace, go to file and save as and make sure you save it as a .vbs file. Then just save the vbs script where ever you like and run the script via cmd or batch file. If you need multiple fonts installed just repeat the objFolder.CopyHere "C:\Scripts\Myfont.ttf" line at the end with each font name in the appropriate place.

I should also mention that the batch file or command should look like this:
Code:
cscript "C:\folder\InstallFont.vbs"

I've tried the first few answers on this forum to no avail and this is the only thing that has worked for me so I thought I'd share.


reference: Hey, Scripting Guy! How Can I Install Fonts Using a Script? - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs

I had the same problem and your way worked for me perfectly! many thanks! :)
 

My Computer

Computer Manufacturer/Model Number
Dell
OS
Windows 7 ultimate 64
CPU
Optiplex 7010
The TechNet article mentions that simply copying a font file to the Fonts folder will not work.
As far as we know, the only programmatic way to get Windows to recognize that a new font has been added to the Fonts folder, and thus get Windows to install that font for you, is to use the Shell object.
Which explains why all the batch files (so far) in this thread don't work (well).


InstallFont.vbs
Code:
strFontToInstall = "C:\PathTo\Some\Font.fon"
Const FONTS = &H14

Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.Namespace(FONTS)
objFolder.CopyHere strFontToInstall

InstallFont(golfed).vbs
Code:
strFontToInstall = "C:\PathTo\Some\Font.fon"
CreateObject("Shell.Application").Namespace(20).CopyHere strFontToInstall


InstallFont.bat
Code:
set font_to_install="C:\PathTo\Some\Font.fon"
(
	echo Set objShell = CreateObject^("Shell.Application"^)
	echo Set objFolder = objShell.Namespace^(20^)
	echo objFolder.CopyHere "%FONT_TO_INSTALL:"=%"
) > "%TEMP%\tmp_%~n0.vbs"
WScript "%TEMP%\tmp_%~n0.vbs"
del "%TEMP%\tmp_%~n0.vbs"

InstallFont(golfed).bat
Code:
set font_to_install="C:\PathTo\Some\Font.fon"
echo CreateObject^("Shell.Application"^).Namespace(20).CopyHere "%FONT_TO_INSTALL:"=%">"%TEMP%\tmp_InstallFont.vbs"&&(WScript "%TEMP%\tmp_InstallFont.vbs"&timeout 1 >NUL&del "%TEMP%\tmp_InstallFont.vbs")


Does anyone know an effective command line to use to place a font into the font folder in Windows 7?
To install a font? Here's your command... (good luck remembering it though)

Command Line command
Code:
echo CreateObject^("Shell.Application"^).Namespace(20).CopyHere "[COLOR="Red"]<PathToFontFile>[/COLOR]">"%TEMP%\tmp_InstallFont.vbs"&&(WScript "%TEMP%\tmp_InstallFont.vbs"&timeout 1 >NUL&del "%TEMP%\tmp_InstallFont.vbs")


And for anyone looking, here's a simple font installer batch file.
Code:
@echo off

REM Drop a font file on me and I'll install it!

set default_font_to_install="C:\PathTo\Some\Font.fon"
if "%~1"=="" ( set font_to_install=%DEFAULT_FONT_TO_INSTALL%) else (
	set font_to_install=%1
)
(
	echo Set objShell = CreateObject^("Shell.Application"^)
	echo Set objFolder = objShell.Namespace^(20^)
	echo objFolder.CopyHere "%FONT_TO_INSTALL:"=%"
) > "%TEMP%\tmp_%~n0.vbs"
WScript "%TEMP%\tmp_%~n0.vbs"
del "%TEMP%\tmp_%~n0.vbs"


(Note: All batch files above use temp files)
 

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
I was able to do this from a network shared folder on our domain for a bunch of fonts using the following batch script. It will copy fonts from a directory into C:\Windows\Fonts\ and then add a registry key for each font.

Code:
copy /Y "[B]location_of_folder_with_fonts[/B]\*.ttf" "C:\Windows\Fonts\"
regedit /s "[B]location_of_folder_with_font.reg[/B]\font.reg"
pause

The font.reg file looks like this:
Code:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"[B]Font_Name#1[/B] (TrueType)"="[B]File_Name#1[/B].ttf"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"[B]Font_Name#2[/B] (TrueType)"="[B]File_Name#2[/B].ttf"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"[B]Font_Name#2[/B] (TrueType)"="[B]File_Name#3[/B].ttf"

Just edit the parts in bold as needed. When this script is ran as admin it works fine and after a reboot, the fonts can be seen in the fonts folder from the control panel.
 

My Computer

OS
Windows 7 Home Premium x64
When this script is ran as admin it works fine and after a reboot [...]
Those are the differences between it and the VBScript solution: the registry solution requires administrative privileges, and also a reboot.
 

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
.VBS to automatically overwrite existing fonts?

Thanks takeitback86! This works like a charm but got a question for you.

If computers have fonts already installed, they will get a Windows notification popup on startup asking if the fonts need to get replaced. Would you know if there is a way to do this automatically (a line of code). I would like the .vbs to overwrite the existing fonts without having user to manually click on YES button for all font notification pop ups?
 

My Computer

Computer type
PC/Desktop
OS
New York
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: ClickFont Download
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Ultimate x64
Back
Top