Jump to content

Unattended Font Installation Utility


Recommended Posts

EDIT: Modified code to allow user to specify directory containing fonts.

I wrote a small utility that can aid in installing fonts during a unattended installation. The utility is silent, in that, it has no display or interface. It will run silently in the background and do it's work then exit. It has only one argument. If the user wishes (it's preferred) the directory containing the fonts to be installed can be specified as the one argument. If no argument is given, it uses the working directory.

How it works

First, it gets a list of all the files in the working/specified directory, then it processes all the ones that have the .ttf (.TTF) extension. After it gets it's list, it copies each of the files to %SYSTEMROOT%\Fonts and creates registry entries for each of the fonts. Unfortunately, I don't know of any available API for Java that can parse a TTF and retrieve the font name, so the entries in the registry are labeled "System Installed Font (# ?)" where ? is the number that font was processed.

After a reboot the fonts are all available with their proper names. So you won't have to worry about opening Word and seeing "System Installed Font (# 12)" in the font selector.

The utility depends on the presence of the REG.EXE tool. If this tool doesn't exist or isn't in your path, the program will fail but will not display any errors.

How to make it work

The whole purpose behind using this tool is so that when the system boots for the first time, the fonts are available without user interaction. So the tool will need to be run during GUI-mode or during RunOnceEx if your setup automatically reboots at the end. Remember: the system must be rebooted before the fonts will appear. That's why it's best to do it during GUI-mode. The best way (according to me) is to run it during [setupParams] in WINNT.SIF.

Here's an example using [setupParams] in WINNT.SIF

...
[SetupParams]
UserExecute="%SYSTEMDRIVE%\Fonts\typer.exe %SYSTEMDRIVE%\Fonts"
...

Here's an example using cmdlines.txt:

D:\ (ROOT OF CD)
-$OEM$
-$$
-$1
-Fonts
-FONT1.TTF
-FONT2.TTF
-another.ttf
-...
-typer.exe
-cmdlines.txt
-fonts.cmd

cmdlines.txt

[COMMANDS]
...
"fonts.cmd"
...

fonts.cmd

%SYSTEMROOT%\SYSTEM\CMDOW @ /HID
@echo off
%SYSTEMDRIVE%
cd Fonts
start /wait typer.exe
exit

That's one way to do it. I'm experimenting with different ways to clean it up so it's completely silent and the end-user is oblivious to what's going on.

The utility was written in Java, but was compiled to native code using GCJ and packed using UPX.

Below is a link to a zipped copy of the native binary. Source is included and will successfully compile and run with Sun Java 1.5 (bytecode) and GNU GCJ 3.4.0 (native and bytecode).

License: You may use this utility as you see fit and may use it's source as you see fit. This utility has NO warranty. I have tested it and it works fine for me, but don't blame me if you use it and it destroys the world.

Note: I've tested it on already-installed systems and on my unattended CD. Both times, the utility performed appropriately.

Download: typer.zip Size: 1.26 MB (1,292 KB)

Edited by tosk
Link to comment
Share on other sites


Seems like a nice little utility.

Are you aware that simply placing the font files into $OEM$\$$\FONTS

or using a selfextracting exe to uncompress into the windows\font folder

will install them just fine and to register them for use all you have to do

is open the %windir%\fonts folder once and close it.

shark

Link to comment
Share on other sites

Yah. I knew you could do that. But doing that you actually have to open Fonts to register them. To me, that kind of defeats the purpose of an unattended install since the fonts aren't actually installed until after setup finishes, the system boots for the first time and the end-user has control.

Besides, I was incredibly bored this weekend and needed a way to kill some time. :P

This is also a small proof-of-concept for a project I'm working on that requires a registry access API in Java.

I'm going to test running it from [setupParams] in WINNT.SIF after I add the ability to specify the font directory as an argument.

Edited by tosk
Link to comment
Share on other sites

Why don't you use the AddFontResource API call in gdi32.dll? In this case You don't need the font name, the API gets and applys the name.

Is this documented anywhere and is it freely available? Or do you know what's required to actually do something like this? Also, is it possible to make the call using rundll32?

Link to comment
Share on other sites

Why don't you use the AddFontResource API call in gdi32.dll? In this case You don't need the font name, the API gets and applys the name.

Is this documented anywhere and is it freely available? Or do you know what's required to actually do something like this? Also, is it possible to make the call using rundll32?

Through some trial and error, I've found that using AddFontResource doesn't work. It has to be called as AddFontResourceA and even then, it doesn't add the appropriate entries to the registry. I'm sure I've just not done something right and that's why it's not working. Any help would be greatly appreciated.

Link to comment
Share on other sites

Why don't you use the AddFontResource API call in gdi32.dll? In this case You don't need the font name, the API gets and applys the name.

Is this documented anywhere and is it freely available? Or do you know what's required to actually do something like this? Also, is it possible to make the call using rundll32?

Most of the font related APIs are documented at http://msdn.microsoft.com/library/default....ontext_9r77.asp

Link to comment
Share on other sites

  • 8 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...