0

Fonts are to be copied into the Windows font folder with a vb script. The fonts are copied with the little script below. The script copys from folder with font-files into Windows Font folder and stops at each box and waits for the event to be clicked. How can this box event be confirmed by script. The solution should look like this: All font files should be copied, overwritten or pasted into the Windows font folder.

Regards Stefan

Const FONTS = &H14&

Set shell = CreateObject("Shell.Application")
Set wshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fontsFolder = shell.Namespace(FONTS)
 
scriptFullName = WScript.ScriptFullName
Set currentFolder = fso.GetFolder (fso.GetParentFolderName(scriptFullName))
 
For Each file In currentFolder.Files
    If fso.GetExtensionName(file.Name) = "ttf" Then
        WScript.Echo "Installing font: " & file.Path
        fontsFolder.CopyHere file.Path
    End If
Next
  • Maybe you should look at [`InvokeVerb("install")`](https://stackoverflow.com/q/49195780/692942). – user692942 Nov 30 '21 at 17:40
  • Solution doesn't work! – user3402511 Nov 30 '21 at 18:13
  • Great feedback, real helpful. What doesn’t work, does it error, if so what is the error? I can guarantee that manually copying the fonts into the system font folder is likely to not work because you still need to "install" the font to register it with the system. – user692942 Nov 30 '21 at 18:23
  • @user692942 The posted code works because it uses Shell.application, as explained here: [Installing Fonts with a VBScript or PowerShell Script](https://www.itprotoday.com/powershell/trick-installing-fonts-vbscript-or-powershell-script). The only issue is the unnecessary **Wscript.echo** line. Also, additional code is needed if the OP wants to check for already-installed fonts. I tried one script that uses InvokeVerb("install") and there was no error, but the fonts were not installed. Maybe that method worked on older Windows versions? – LesFerch Dec 01 '21 at 13:33

1 Answers1

1

To eliminate the prompt on each font install, just remove or comment out the WScript.Echo line. You'll still see a notice with a progress bar for each font, but there will be no OK button to press.

Alternatively, you can run the code using CScript.exe (as was probably intended) and then the WScript.Echo will just generate output in the console without a prompt.

To eliminate the Yes/No prompt that appears if the font is already installed, you'll need to add code to check if the font is already installed. See: More easy way to show if a Font is installed or not (see the VBScript code posted in the question).

Note: The code at that link depends on having the font's "friendly name". If you just want to do a check based on the font file name, you can simply check if the file already exists in C:\Windows\Fonts or %LocalAppData%\Microsoft\Windows\Fonts. In general, if the file is there, the font is installed. It's a quick and easy way to check.

Here is the complete edited script (You can uncomment the WScript.Echo lines if running via CScript.exe):

Const FONTS = &H14&

Set shell = CreateObject("Shell.Application")
Set wshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fontsFolder = shell.Namespace(FONTS)

WinFonts = "C:\Windows\Fonts\"
UserFonts  = wshShell.ExpandEnvironmentStrings("%LocalAppData%") & "\Microsoft\Windows\Fonts\"

scriptFullName = WScript.ScriptFullName
Set currentFolder = fso.GetFolder (fso.GetParentFolderName(scriptFullName))

For Each file In currentFolder.Files
  If fso.GetExtensionName(file.Name) = "ttf" Then
    If fso.FileExists(WinFonts & file.Name) Or fso.FileExists(UserFonts & file.Name) Then
      'WScript.Echo "Already installed: " & file.Path
    Else
      'WScript.Echo "Installing font: " & file.Path
      fontsFolder.CopyHere file.Path
    End If
  End If
Next
LesFerch
  • 1,540
  • 2
  • 5
  • 21