0

Here is my script based on How do I install a font from the Windows command prompt?

Dim WinFontDir
Dim SrcFontDir
WinFontDir = "C:\Windows\Fonts"
SrcFontDir = "..\fonts.test"


Set objShell = CreateObject("Shell.Application")
Set objFontFolder = objShell.Namespace(WinFontDir)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSrc = objFSO.GetFolder(SrcFontDir)
Set colFiles = objSrc.Files
For each objFile in colFiles
    If objFSO.FileExists(WInFontDir + "\" + objFile.Name) Then
        WScript.Echo objFile.Name 
    else
        WScript.Echo "Copying " + objFile.Name
        objFSO.CopyFile SrcFontDir + "\" + objFile.Name, WinFontDir + "\" + objFile.Name
        Set objFolderItem = objFontFolder.ParseName(objFile.Name)
        objFolderItem.InvokeVerb("Install")  // <- exception
    End If
Next

Basically I want to be able to iterate through a folder of fonts, and only copy and install if a font file does not exists in "C:\Windows\Fonts" in the first place.

But when it comes to this line objFolderItem.InvokeVerb("Install") I got this error message:

Object Required: 'objFolderItem'

What is the cause?

Anthony Kong
  • 5,318

1 Answers1

0

At the end, only this way works for me:

Dim WinFontDir
Dim SrcFontDir
WinFontDir = "C:\Windows\Fonts"
SrcFontDir = "..\fonts"

Set objShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSrc = objFSO.GetFolder(SrcFontDir)
Set colFiles = objSrc.Files
For each objFile in colFiles
    If Not objFSO.FileExists(WInFontDir + "\" + objFile.Name) Then
        WScript.Echo "Copying " + objFile.Name
        FONTS = &H14&
        Set objFontFolder = objShell.Namespace(FONTS)
        objFontFolder.CopyHere objFile.Path
    End
Next

Note: Only copy files that do not exist in the font folder

Anthony Kong
  • 5,318