Installing Fonts – Batch Script

An easy way to install a folder of fonts from an (elevated) batch script. I’ve compiled this from a couple different sources, into a single subroutine. It avoids duplicate fonts and their warning messages which require user interaction.

:: Install Fonts
CALL :INSTALL_FONT "\\Server\Share\Fonts"

GOTO END

::SUBROUTINES
:INSTALL_FONT
set strNewFontsFolder=%1
(
	echo Set fso = CreateObject^("Scripting.FileSystemObject"^)
	echo Set stdout = fso.GetStandardStream^(1^)
	echo stdout.WriteLine "Installing fonts from: " ^& "%strNewFontsFolder:"=%"
	echo Set objShellApp = CreateObject^("Shell.Application"^)
	echo Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
	echo Set objFolder = objShellApp.Namespace^(20^)
	echo If objFSO.FolderExists^("%strNewFontsFolder:"=%"^) = True Then
	echo 	For Each objFile In objFSO.GetFolder^("%strNewFontsFolder:"=%"^).Files
	echo 		If UCase^(Right^(LCase^(objFile.Name^), 4^)^) = ".TTF" Then
	echo 			If objFSO.FileExists^(objFolder.Self.Path ^& "\" ^& objFile.Name^) = False Then objFolder.CopyHere objFile.Path
	echo 		End If
	echo 		If UCase^(Right^(LCase^(objFile.Name^), 4^)^) = ".FON" Then
	echo 			If objFSO.FileExists^(objFolder.Self.Path ^& "\" ^& objFile.Name^) = False Then objFolder.CopyHere objFile.Path
	echo 		End If
	echo 	Next
	echo End If
) > "%TEMP%\tmp_%~n0.vbs"
cscript //nologo "%TEMP%\tmp_%~n0.vbs"
del "%TEMP%\tmp_%~n0.vbs"
EXIT /B

:END

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: