How to install fonts through the Registry

R

rolszyk

I need to be able to install fonts from a batch script onto many user's
computers and it seems to work sometimes. Some fonts will install, or
all the fonts will install, or none will install, and it is always at
random. I add the registry keys and I also add the fonts to the
c:\winnt\fonts folder. I want to be able to run a batch script that
installs certain fonts on a computer. If there is an easier way than
the registry, please let me know. Thanks.
 
M

Micky

rolszyk said:
I need to be able to install fonts from a batch script onto many user's
computers and it seems to work sometimes. Some fonts will install, or
all the fonts will install, or none will install, and it is always at
random. I add the registry keys and I also add the fonts to the
c:\winnt\fonts folder. I want to be able to run a batch script that
installs certain fonts on a computer. If there is an easier way than
the registry, please let me know. Thanks.

The "correct" way is to call the GDI function, AddFontResource()
or AddFontResourceEx(). Although you can't call these functions
from a batch file, you can easily create a little helper EXE that'll
handle the call for you. Your batch file need only call the EXE,
passing the filename (the font file itself) as a parameter.
 
R

rolszyk

Is there any way to install the fonts through the registry or is this
the only way?
 
M

Micky

rolszyk said:
Is there any way to install the fonts through the registry or is this
the only way?

No -- font registration involves more than simply copying a
font file and updating the registry. The shell must be notified
of the change for the change to take effect immediately. With
AddFontResource() you can also add fonts temporarily, as
one might do when running a CD-ROM front-end. When
the front-end terminates, the font is removed from the system.

Creating an EXE to perform the job of registering any given
font is trivial in the extreme, but if you don't have the required
tools or knowledge I'm sure you'll find someone has already
written one and made it available. Google and see.
 
R

rolszyk

Could you suggest a sample EXE for me and also what would I have to
write it in?
 
M

Micky

rolszyk said:
Could you suggest a sample EXE for me and also what would I have to
write it in?

I wrote an ADDFONT.EXE in around 5 minutes using MS VS C++.

The salient portion of code is:-

if(CopyFile(szSource, szDestination, TRUE))
{
AddFontResource(szSource);
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
}

....where szSource is the full path to the source font file
and szDestination is the full path to the same file within
the fonts folder.

First it checks to see if the file exists in the fonts folder. If it
already exists then no action is taken. Otherwise the font is
copied and registered, and the shell is notified of the font
change.

To use it, you'd place all your fonts, the batch file and the exe
in the same folder. The batch file would then contain script
such as:

@echo off
addfont myfont.ttf
addfont yourfont.ttf
addfont theirfont.ttf

If you're unable to write your own EXE, let me know and I'll
upload an improved version for you. It's currently 13KB with
very basic error checking, but I'm prepared to spend a little
more time crossing the Ts and dotting the lower-case Js if it
helps you.
 
R

rolszyk

Thank you for the suggestion. We are currently trying this to see if it
works. I will let you know if it doesn't work. Any other ideas are
greatly appreciated. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top