Ayse Ayse - 10 days ago 7
Python Question

Python version of AddFontResource()

I'm currently trying to install fonts across a bunch of servers. I've been able to use a script to copy the fonts over and "install" them onto the server but I need to be able to access the fonts without having to turn off the server or log off the account.

I found Windows

AddFontResource()
which is done using C++, but is there an equivalent function in Python or Powershell?

(I've been using Python and Powershell to do checks and installations.)

Answer

Have you tried using the win32api library? It has the SendMessage() function which can be used in conjunction with the windll.gdi32.AddFontResource() in ctypes

For example installing a TTF font file:

import win32api
import ctypes
import win32con


ctypes.windll.gdi32.AddFontResourceA("C:\\Path\\To\\Font\\font.ttf")
win32api.SendMessage(win32con.HWND_BROADCAST, win32con.WM_FONTCHANGE)
Comments