Categories
Geeky/Programming

Installing Fonts Programmatically on Windows

Working on a project, I came across the need to install a font on a machine. Now, manually, you can just right click on the font->install. Or I am pretty sure you can just copy into %windir%fonts and it then it works, but it might not be usable until you reboot, I am not a font expert here so don’t quote me, but just from what I have been reading in the forums.

Now, to install a font programmatically, you can just copy it into the folder, but what if you want it usable right away? um… Well, some people say there are some reg keys you need to run, etc. But I came across another very undocumented app that Microsoft has: fontinst.exe

You can just call this program and pass in an .inf file as parameter and it will install the font for you.

The inf file is formatted like:

[fonts]
My Font Name.TTF

now, to call it, you can run “fontinst.exe /F MyFontName.inf” (if you saved the file as MyFontName.inf)

C++ Code:

ShellExecute( NULL, “open”, C:MyPathfontinst.exe”, ” /F MyFont.inf”,C:MyPath”, SW_HIDE );

And it should install your font!

Note: I think you can do multiple fonts in one .inf file, I didn’t try it because I didn’t need to install more than one at a time, but I read on the forums and such that it is possible.

Technorati tags: , , , , ,

By Steve Novoselac

Director of Digital Technology @TrekBikes, Father, Musician, Cyclist, Homebrewer

5 replies on “Installing Fonts Programmatically on Windows”

I always just use AddFontResource — the only time the fonts I use are needed are when my application is running. But this way, I don’t clutter up the system font table with my own fonts (I remove font when the app closes).

The other trick is to use AddFontResource to make it available, and then update the registry entry for it manually.

http://support.microsoft.com/kb/102960/en-us
http://msdn2.microsoft.com/en-us/library/ms534231.aspx

Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.