How do I remove fonts from my code on Windows?

In this article, I showed how to install fonts from a script, but now I am facing the problem of removing them. How can i do this? Any language is fine, I will convert the information to what I need later.

EDIT: Ok, so now I know how to remove fonts (for the most part). I go out to the challenge RemoveFontResource

. After that I use SendMessage

with parameters: 0xffff,0x001D,0,0

(HWND_BROACAST, WM_FONTCHANGE ... and I forgot what the other two parameters are worth). The thing is, this removes the font, but in the entry, the Control Panel

Fonts

font still appears there (even if you try to delete it there too, it will say that it cannot read from the original file or disk.

So basically, I remove the font in the following order:

  • physically removed from C:\Windows\Fonts

  • call RemoveFontResource
  • call SendMessage

What is the correct way to delete?

+2


source to share


3 answers


From all the documentation I've ever seen, these three lines of code are the "correct" way to do it, but as we well know this doesn't quite work - as expected.

RemoveFontResource(fontPath);               
DeleteFile(fontPath);
::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

      

REBOOT

I followed the above code and duplicated your problem (the control panel still shows the font, however the font file is gone). Then I rebooted. The font has now disappeared from the Fonts control panel applet.

Something else to note: although the control panel was still showing the font as "there" applications no longer listed it in their font lists (I specifically tried Wordpad before and after removing webdings.ttf - no reboot)



Yes, I know - rebooting is a bad solution, especially if you need to update the font since you cannot reinstall it (via the control panel anyway - it claims the font is still installed) until you reboot after uninstalling it ( I tried).

However, if all you want to do is remove the font - that's not the worst solution - the font will essentially disappear after you remove it (apps don't see it, it's only visible in control panel panes as far as I can tell) and you don't need to force restart.

From SDK Help on RemoveFontResourceFont (which may indicate why odd parity is observed)

If there are great references to a font, the associated resource stays loaded as long as the device context uses it.

+4


source


Once you find the actual filename as mentioned in Havenard and using the referenced article, you can do

objFSO.DeleteFile(FontFilePath);

      

where FontFilePath is the path to the file you want to delete.

More details here: technical article



The problem you might run into, which I didn't think about until I saw your comment, is that the program might need a font for a specific element. All known system fonts are stored in the registry. If you remove the font, you must also remove the key from the registry. The registry paths are as follows

Windows 95
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts]

Windows NT
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]

      

The keys are as follows:

Key name = Full name of the font
Key type = REG_SZ
Key Value = name of font file

      

+4


source


All your fonts can be found in the C: \ WINDOWS \ Fonts \ folder

Explorer will mask this folder to display font names instead of real filenames, but that's all there is. You can edit and comment out the lines C: \ WINDOWS \ Fonts \ desktop.ini to disable this feature and open the font files (you may need to open the explorer again for it to take effect).

+1


source







All Articles