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.
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
LikeLike
that is good to know, yeah this will be the one stop shop font post ๐ – I didnt know about AddFontResource, but yeah, I need my fonts to be on the machine foreva! ๐
LikeLike
hmm…
i thought you just had some one-word magic command you plugged into that application to make the fonts magically install.
=}
LikeLike
Only works on 32 bit systems, sorry.
LikeLike
fontinst.exe no longer seems to be available, but there is FontReg.exe, which can be found on the internet. Very similar, and runs on 32 or 64 bit.
LikeLike