Hey, Scripting Guy! How Can I Install Fonts Using a Script?

Hey, Scripting Guy! How Can I Install Fonts Using a Script?

  • Comments 16
  • Likes
Hey, Scripting Guy! Question

Hey, Scripting Guy! Is there any way I can install a font using VBScript?
-- RS

SpacerHey, Scripting Guy! AnswerScript Center

Hey, RS. As a general rule, the Scripting Guy who writes this column steers clear of popular culture. (Actually, it’s not just a general rule; popular culture has a restraining order which requires him to stay at least 100 yards away from it at all times.) Nevertheless, every now and then he accidentally stumbles upon a bit of popular culture that absolutely fascinates him.

For example, just this morning he read about a movement to remove the apostrophe from the English language. As near as he can tell, there are two primary concerns that people have with the apostrophe. For one, they believe the apostrophe is way too hard to use; therefore, it should be eliminated. (This, by the way, is how you can tell that Americans are behind the movement to eliminate the apostrophe: if something is hard, then don’t do it. That’s the American way!)

The other argument is this: no one uses apostrophes in text message. (You say they do use apostrophes? we say they dont.) According to this theory, text messaging is becoming more and more popular; therefore, we should adopt the same grammar, syntax, and spelling used in text messaging.

Because, as most people would agree, text messaging should be the ultimate arbiter when it comes to the English language.

Note. Apparently text messaging is not just influencing the use of apostrophes; it’s also influencing the names that parents bestow on their children. As a public service for those of you expecting a new bundle of joy, you can find a handy list of text messaging acronyms and shorthand codes right here. Please give little An our best. (An, by the way, is short for Ann, apparently because a three-letter name like Ann needs to be trimmed down a bit.)

Here’s a true story for you. The Scripting Guy who writes this column once worked with an editor who was also opposed to the apostrophe, but for a different reason: she didn’t – sorry, she did not – believe that any word containing an apostrophe was a real word. Can’t? Not a real word; it should be “cannot.” Doesn’t? Not a real word; it should be “does not.” Debra’s computer? Not a real phrase; it should be “the computer belonging to Debra.” Ah, good times ….

Note. What about the phrase “the hard disk belonging to the computer?” Turns out that’s not a real phrase, either. Why not? Because “computers are inanimate objects and cannot possess anything.” Which seems odd to us. After all, Scripting Guy Dean Tsaltas is pretty much an inanimate object, and he possesses all sorts of things.

So how does any of that help you install a font using VBScript? Well, to be honest, we’re not sure that it does. But this should help a little:

Const FONTS = &H14&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FONTS)
objFolder.CopyHere "C:\Scripts\Myfont.ttf"

As it turns out, there’s nothing particularly difficult about installing a new font. Suppose you have a font file named C:\Scripts\Myfont.ttf. How can you install that font? Here’s one simple way: just drag the font into your Fonts folder. As soon as the font has been added to the folder, the operating system will immediately install the font for you.

Which, now that we think about it, is pretty cool, isn’t it?

Of course, that might also get you to thinking; in fact, you might be thinking, “Hey, all I have to do is copy a font into the Fonts folder and that font will automatically be installed for me.” And that’s true, but with one very important caveat: you must copy the file using the Shell object. Admittedly, you can use WMI or the FileSystemObject to copy a file into the Fonts folder; however, when you do so the operating system will not automatically install the font for you. As far as we know, the only programmatic way to get Windows to recognize that a new font has been added to the Fonts folder, and thus get Windows to install that font for you, is to use the Shell object.

Note. And yes, that does make it a bit of a sticky wicket to try and install fonts on a remote computer; after all, the Shell object isn’t designed to work against remote computers. One possible solution? Put your font-installing code in a logon script; after all, logon scripts always run locally. A less-elegant solution would be to copy the fonts to a remote machine, then instruct the user at that remote computer to open and close their Fonts folder. Opening and closing the Fonts folder has the net effect of installing any new fonts that are in the folder but not yet installed.

Like we said, that’s not very elegant. But it’ll work.

As for the script itself, we start out by defining a constant named FONTS and setting the value to &H14&; we’ll use this constant to tell the script which “special folder” (i.e., the Fonts folder) we want to work with.

Note. Couldn’t we just use a hardcoded path like C:\Windows\Fonts to represent the Fonts folder? Sure. However, keep in mind that the Fonts folder doesn’t have to be C:\Windows\Fonts. By using the special folders constant the script will always find the Fonts folder for us, regardless of where that folder actually lives.

After we define the constant we create an instance of the Shell.Application object, then use the following line of code to bind to the Fonts folder:

Set objFolder = objShell.Namespace(FONTS)

Once we’re connected to the Fonts folder all we have to do is call the CopyHere method, specifying the complete path to the font we want to install:

objFolder.CopyHere "C:\Scripts\Myfont.ttf"

It’s that easy. And yes, now that you mention it, this script does work on Windows Vista; just make sure you run the script as an Administrator. Otherwise you’ll get a security popup asking you if you really do want to copy a file to the Fonts folder.

But the heck with fonts; let’s get back to something people really care about: apostrophes. As a Microsoft employee, the Scripting Guy who writes this column isn’t supposed to take a stand on controversial issues, at least not when publishing articles on Microsoft.com. Nevertheless, he’s going to go out on a limb here and state – for the record – that he believes the apostrophe should continue to be used; he’d just like to see it used a bit more correctly. Being out of touch with the way things are done these days, the Scripting Guy who writes this column still hasn’t come to grips with words spelled any which way the writer pleases, nor with apostrophes put in the wrong places.

In fact, in researching this article (yes it is kind of hard to believe that a article like this is researched, isn’t it) the Scripting Guy who writes this column discovered there’s a technical term for the wanton use of apostrophes: greengrocer’s apostrophes, a name bestowed in honor of grocery stores that have signs like “Banana’s: 5 for a Dollar” and “Hamburger and Hot Dog Bun’s Half-Price.” If you have the stomach for it (and an old-fashioned curmudgeon like the Scripting Guy who writes this column really doesn’t) you might check out the Apostrophe Abuse Web site. Some of the examples there will curl your hair.

And, if you’re lucky, will give you a name for your new baby as well.

Historical footnote. Former US President Andrew Jackson once stated that he had “little respect for a man who can only think of one way to spell a word.” Historians are unsure of Jackson’s view on apostrophes; we’ll continue to research this and keep you posted.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Hey that's great - now how do I permanently remove a font from the system with a similar script? Oh ya, I need to do it for about 6,000 computers too, but if I get the basics I can figure out how to get it to all of them. Thanks,

    +Jonathan

  • when installing PFB+PFM files (postscript files) you need a little trick to make it working - because the above solution will just throw errors.

    1) copy the PFB file to the fonts folder (Copy-Item "C:\Scripts\Myfont.PFB" -destination "$Env:Windir\fonts"

    2) install the PFM file as noted in this article (objFolder.CopyHere "C:\Scripts\Myfont.PFM"

    voilà!

    steirer

  • How can i use this script to install multiple fonts..?

  • I have a script to deploy fonts in the method described above but have found that, post install, the fonts names are missing from the font drop down menu in Word and Excel.

    Operating System is Windows XP

    Office suite is Office 2003

    Font types are Open Type

    Default printer is an HP 8000 series

    I have found that the font names are restored if I run an Office Profile wizard against a backup OPS file. But I cant exactly do that for 5000+ computers. Any ideas?

  • Ok, I found the answer to the missing font names. Remove the following registry key:

    HKCU\Software\Microsoft\Office\Common\FontBmpCacheDisable

    The next time the machine restarts the cache is recreated and the font names become visible, sorted. Hope someone finds this helpful. Great article btw, thanks all.

    PS. Edit the registry at your own risk, any probs not my fault etc.

  • There is no need to copy the .PFB file to the Font folder. When the .PFM font is installed, it will automatically install the .PFB file as well...

    Mass installation in a loop should avoid trying to install the .PFB files as fonts as it may cause errors and break script execution...

  • If you are looking for an easy way to intall fonts in windows 7 with a little script.

    you can find it for free on our page:

    www.cloudtec.ch/.../install-font-command-line-script-windows-7.html

    Chers

  • Is there a way to run this silently so the "installing font ... " does not appear?

  • hi, thanks for the informative script, is there any script that can remove the fonts as well?

  • Still no way of installing without needing an administrator to hand? Still no good then.... :(

  • Hi,

    do you know this: theoatmeal.com/.../apostrophe

    I started Wordpad after installing my fonts, but it showed no new fonts. I tried restarting explorer but this did not work neither. After reboot the fonts was showed also in the editor. Why? Can I notify my applications about the new fonts other than rebooting?

    Thank you + greetings,

    Mayra

  • Example for lots of fonts using "CopyHere":

    wpkg.org/Fonts

    @cloudtec IT-Services Bern:

    InvokeVerb("Install") does not work for me, because it seems to needs desktop interaction (popup).

  • using bat and reg files:

    windowsitpro.com/.../how-can-i-install-font-command-linebatch-file

  • Hello Scripting Guy, I know this is a very old reply, but I had a question. I am using this Script to install fonts on multiple computers and it works great. The only problem I have is that if there are many fonts to be installed, you need to sit at the desk and hit 'ok' to install on every instance. Is there a way to automate this part? Maybe even without the user seeing the VB popups?

  • I have now spent far too long looking for a software packager and installer to do 3 things : install fonts in the user's machine, register a file type with an icon and associate that file type with the program so that when a file is double clicked it loads into the started up program.

    If you work for Microsoft, send a memo (obviously with a Microsoft logo) to the 'team' responsible for the net set of programs and advise them that their setup installer they put together with those programs is lame at best