views:

336

answers:

4

This article showed me how to install fonts from a script, but now I'm faced with the problem of removing them. How can I do that ? Any language is ok, I'll convert the info to what I need later.

EDIT: Okay, so I now know how to uninstall fonts ( most of the part at least ). I'm issuing calls to RemoveFontResource. After that I use SendMessage with parameters: 0xffff,0x001D,0,0 ( HWND_BROACAST,WM_FONTCHANGE ... and I forgot what the other two parameters stand for ). The thing is, this deletes the font, but in the Control Panel's Fonts entry, the font still appears there ( even though if you try to delete it from there as well, it will say it cannot read from source file or disk.

So basically, I'm deleting a font in this order:

  • deleting physically from the C:\Windows\Fonts
  • calling RemoveFontResource
  • calling SendMessage

What's the proper way of uninstalling?

+1  A: 

All your fonts can be found at C:\WINDOWS\Fonts\

Explorer will mask this folder to display the font names instead of the real file names, but its all there. You can edit and comment out the lines of C:\WINDOWS\Fonts\desktop.ini to disable this feature and reveal the font files (maybe you need to reopen the Explorer to take effect).

Havenard
+4  A: 

Once you find the actual filename as Havenard mentioned and using the article you mentioned you can do a

objFSO.DeleteFile(FontFilePath);

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

More Info here: technet article

A problem that you may run into, which I didn't think of until I saw your comment, is that a program may require that font for some particular item. All known system fonts are stored within the registry. If you remove a font, you should also remove the key from the registry. 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 followed:

Key name = Full name of the font
Key type = REG_SZ
Key Value = name of font file
Scott
I could just use a delete call. I was wondering if other steps would be involved ( like the registry ).
Geo
+1  A: 

I account the same question, this is my code below:

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

But the problem is the font still exist in the 'Fonts' folder, after i deleted the font file. Could anyone help me to solve this situation? Thanks!

elvee
I reached the same code a while ago. I'm confronting with the same problem. The font still appears in the Fonts folder.
Geo
+1  A: 

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

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

REBOOT

I executed the code above and duplicated your problem (control panel still shows the font, however the font file is gone). I then rebooted. Now the font is gone from the Fonts Control Panel applet.

Something else to note: even though control panel still showed the font as "there" applications no longer listed it in their font lists (I specifically tried Wordpad, before and after deleting webdings.ttf - without rebooting)

Yea i know - rebooting is a poor solution - especially if you need to update the Font since you can't reinstall it (via the control panel anyways - it claims the font is still installed) until you reboot after removing it (I tried).

However if all you want to do is remove the font - its not the worst solution - the font is essentially gone after you uninstall it (apps don't see it, its only visible in control panel fonts as far as i can tell) and you wouldn't need to force a reboot.

From the SDK help on RemoveFontResourceFont (which may indicate why the oddness is seen)

If there are outstanding references to a font, the associated resource remains loaded until no device context is using it.

Ruddy
Yeah, but this should be done by an automated process. Rebooting kind of isn't an option.
Geo
So a little further investigation seems to point to the WMI service. If you restart that service *after* the font is deleted the control panel font list is correct (NOTE: if you have c:\windows\fonts folder open in explorer when you do the restart WMI service and just press F5 it *still* shows it, but exit and restart the fonts control applet and you'll see its gone AND you can re-install the font) all without a reboot... Further Note: I tried deleting the font when the WMI service wasn't running and it wasn't until it was started again that deleted font was removed from the control panel.
Ruddy
Can you also list the command to restart the WMI service? Can it be done from the command line?
Geo
You can use the net command to this from a command line. You can find the service name on the service properties page in the services control panel app for the the specific service. For WMI: `net stop wmiapsrv` to stop it, `net start wmiapsrv` to start it (AFAIK there isn't a restart command)
Ruddy
Thank you for your effort. This really helped.
Geo