Installing Fonts with command line script

Many large corporations need to deploy fonts to a large number of computers. However some administrator opt not to use the installer provided. Instead, they want to install the fonts only using a script.

The script below is written in VBScript. It looks into the shared directory \\media-server\FileFolder\fontsourcefolder\ for any files with .ttf extension. It then installs every file found, unless it is already existed in the local machine's font folder.

Option Explicit
Dim objShell, objFSO, wshShell
Dim strFontSourcePath, objFolder, objFont, objNameSpace, objFile

Set objShell = CreateObject("Shell.Application")
Set wshShell = CreateObject("WScript.Shell")
Set objFSO = createobject("Scripting.Filesystemobject")

Wscript.Echo "--------------------------------------"
Wscript.Echo " Install Fonts "
Wscript.Echo "--------------------------------------"
Wscript.Echo " "

Const EVENT_SUCCESS = 0
Const EVENT_CRITICAL = 1
Const EVENT_WARNING = 2
Const EVENT_INFO = 4 

strFontSourcePath = "\\media-server\FileFolder\fontsourcefolder\"

wshShell.LogEvent EVENT_INFO, "Installing font - invoke startup script "

If objFSO.FolderExists(strFontSourcePath) Then

Set objNameSpace = objShell.Namespace(strFontSourcePath)
Set objFolder = objFSO.getFolder(strFontSourcePath)

For Each objFile In objFolder.files
 If LCase(right(objFile,4)) = ".ttf" Then
  If objFSO.FileExists(wshShell.SpecialFolders("Fonts") & "\" & objFile.Name) Then
   Wscript.Echo "Font already installed: " & objFile.Name
   wshShell.LogEvent EVENT_INFO, "Font already installed: " & objFile.Name
  Else
   Set objFont = objNameSpace.ParseName(objFile.Name)
   objFont.InvokeVerb("Install")
   Wscript.Echo "Successfully Installed Font: " & objFile.Name
   wshShell.LogEvent EVENT_SUCCESS, "Successfully Installed Font: " & objFile.Name
   Set objFont = Nothing
  End If
 End If
Next
Else
 Wscript.Echo "Font Source Path does not exists"
End If

To execute the script, open a command prompt and enter:

cscript <path-to-script>

Notes

  • This script requires administrator privilege. On Vista and above with UAC turned on, the UAC prompt will pop up. To eliminate it, open an Administrator console first, then execute the script.

  • It is possible to execute the script using GPO policy at computer start-up. You can find instruction at: Assign computer start up scripts. Note that the fonts location and script must be accessible by the computer account. Usually this can be done by adding Domain Computers account into the security/share permission list.

  • Race condition may exists for a computer start up script. For reliable execution, it is recommend to perform on an interactive console (after logged in).