[ TechHome ]

Install a font

The C:\Windows\Fonts is a special folder. If you copy the font file to C:\Windows\Fonts using the FileCopy function, the font file will be copied to the C:\Windows\Fonts folder, but will not be installed. Here is a trick that uses the Windows Shell Install verb to install the font:
 
SourcePath = '\\server\share'
FontFileName = 'sample.ttf'
objShell = CreateObject("Shell.Application") 
objFolder = objShell.Namespace(SourcePath)
objFolderItem = objFolder.ParseName(FontFileName) 
colVerbs = objFolderItem.Verbs 
ForEach objVerb in colVerbs
   If StrIndexNC(objVerb.name,'&I',1,@FWDSCAN) != 0 || StrIndexNC(objVerb.name,'Install',1,@FWDSCAN) != 0
      objVerb.DoIt
      Break
    EndIf
Next
Reference:http://blogs.technet.com/b/rspitz/archive/2010/09/25/how-to-install-a-font-from-the-command-line-on-windows-7.aspx


This sample shows how to install a font on NT/2000/XP+ systems. This example assume the font file is myfont.ttf in the current directory, and the title of the font is "My Font (TrueType)"


;Installing a font in Windows NT/2000/XP
   ;----------------------------------------
   ;Get path to font directory and copy font

   FontDir=RegQueryEx(@REGCURRENT,"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders[Fonts]","",1)
   FileCopy("myfont.ttf",FontDir,@FALSE)

   ;Register font
   FontKey=RegOpenKey(@REGMACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts")
   RegSetValue(FontKey,"[My Font (TrueType)]","myfont.ttf")
   RegCloseKey(FontKey)

   ;Add the font to the font system
   DllName=StrCat(DirWindows(1),"gdi32.dll")
   DllCall(DllName,LONG:"AddFontResourceA",lpstr:"myfont.ttf")

   ;Inform running apps about the new font
   IntControl(22,-1,29,0,0)

;The last line is only needed if currently running applications should be informed about the
;font addition. All apps started after the installation will recognize the new font even
;without the IntControl call. 


Article ID:   W15985
File Created: 2017:07:28:13:00:12
Last Updated: 2013:10:15:08:55:48