Article

bkeadle's picture

Automated Font Registration

Author Info

30 July 2009 - 3:58pm
Submitted by: bkeadle

article
Reads:

1031

Score:
0
0
 
Comments:

3

I needed a way to automate the distribution of fonts (TrueType) fonts via a script. I was surprised to discover that it's not as easy as just copying the font files to the %windir%\fonts folder. Searching around on the Internet, I see that it's not so uncommon to want to be able to do this, but surprisingly, I found no free solution for accomplishing this task - and the programmatic way is over my head.

Typically, to install and register a new Windows font, you have to use Explorer, browse to the Windows Fonts directory, then use the Install New Font... menu item.

However, I discovered something interesting. You can just copy the TTF files from DOS into the font directory (%windir%\fonts), then if you open explorer to the fonts directory the new fonts will automatically get registered. So, this could be scripted like this:

copy *.TTF %Windir%\fonts /y
explorer /e, %Windir%\fonts

And the fonts would successfully be added to the system. However, it isn't exactly silent. The user is left with a Windows Explorer window open that they would need to then close.

I wanted a more silent way to do this. Same concept, except I launch explorer in a hidden window (using my RunHide program), then kill the process silently. Thus, you can silently add new fonts programmatically by:

copy *.TTF %Windir%\fonts
copy %windir%\explorer.exe %temp%\xpl.exe /y
runhide %temp%\xpl.exe /e,%windir%\fonts
ping localhost -n 5 >nul
taskkill /im xpl.exe /f

Kludgy, but it'll work and without any user interaction (or notice).

NOTE:

  • The "ping" line causes a 5 second delay, time for explorer to launch
  • You will need to have Explorer configured to launch as a separate process for this solution to work:

Author Info

30 July 2009 - 3:58pm
Submitted by: bkeadle




User Comments

Another silent method

Submitted by jason_ee on 3 August 2009 - 2:56pm.

Another silent method I use is to distribute each font file and its registry entry. On Windows 2000 and XP, this is in the key HKLM/Software/Microsoft/Windows NT/CurrentVersion/Fonts. Each font has a string in the form of "visible name (font type) = font file name". Note that this method requires handling each font individually and may require a logoff/on cycle or reboot in order for Windows to present the new font(s) to the user.

A VBS method

Submitted by grahamch on 4 August 2009 - 11:58am.

I just had this issue (how to push out a font through NAL). I utilized the following script as a "Run before Distribution" script.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set oApp = createobject("shell.application")

cFonts = &H14&

set oFontsFolder = oApp.namespace(cFonts)
oFontsFolder.copyhere "==path to the location of the font file=="
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Interesting. Sounds strange

Submitted by kellt900 on 3 November 2009 - 2:37am.

Interesting. Sounds strange wanting to delete fonts, but I mused this with some of my geeky colleagues. However interesting train of thoughts here that may apply down the line to other things.

© 2009 Novell, Inc. All Rights Reserved.