Search code examples
vbscriptwindows-xp

Script to Install Font in Windows XP


I am trying to install fonts in windows XP using a VBScript. But for some reason my script works fine in Windows 7 but does not work in Windows XP. I need to install fonts without a system reboot so, I had to choose this approach instead of other registry change approaches which would need a system reboot. Here is my VBScript

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("D:\Logs\")
Set objFolderItem = objFolder.ParseName("Roboto-Italic.ttf")
objFolderItem.InvokeVerb("Install")

My guess is the InvokeVerb("Install") command is not working in Windows XP. In that case are there any alternatives? Please guide me Thanks...


Solution

  • Next script (a code snippet) should work on (obsolete) Windows XP:

    Const ssfFONTS = &H14&
    
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(ssfFONTS)
    objFolder.CopyHere "D:\Logs\Roboto-Italic.ttf"
    

    If the font is already installed then you could be prompted to overwrite it. Not sure whether or not reboot required using above approach...

    See ShellSpecialFolderConstants enumeration

    Specifies unique, system-independent values that identify special folders. These folders are frequently used by applications but which may not have the same name or location on any given system.

    Among others:

    • ssfFONTS 0x14 (20). Virtual folder that contains installed fonts. A typical path is C:\Windows\Fonts.

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

    As soon as the font has been added to the folder, the operating system will immediately install the font for you...
    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.