WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

DllCall Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Font Installation


Question:

We have to distribute set of fonts to about 200 NT Workstations. Is there a way to automate font installation on the clients via script without having to visit every Desktop?

Answer:

On Windows 7 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

Answer (older) :

;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:   W15929
File Created: 2013:10:15:09:54:18
Last Updated: 2013:10:15:09:54:18