在 Windows 下如何从我的代码中删除字体?
本文向我展示了如何从脚本,但现在我面临着删除它们的问题。我怎样才能做到这一点?任何语言都可以,我稍后会将信息转换为我需要的信息。
编辑:好的,所以我现在知道如何卸载字体(至少是大部分)。我正在向 RemoveFontResource
发出调用。之后我使用带有参数的 SendMessage
: 0xffff,0x001D,0,0
( HWND_BROACAST,WM_FONTCHANGE ...我忘记了其他两个参数代表什么)。问题是,这会删除字体,但在控制面板
的字体
条目中,该字体仍然出现在那里(即使您尝试从那里删除它,因为好吧,它会说它无法从源文件或磁盘读取,
所以基本上,我按以下顺序删除字体:
- 从
C:\Windows\Fonts
物理删除 - 调用RemoveFontResource
- 调用SendMessage
什么是正确的卸载方法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从我见过的所有文档中,这三行代码是执行此操作的“正确”方法,但众所周知,它并不像预期的那样完全有效。
重新启动
我执行了上面的代码并重复了您的问题(控制面板仍然显示字体,但字体文件消失了)。然后我重新启动。现在该字体已从字体控制面板小程序中消失。
还有其他需要注意的事情:即使控制面板仍然将字体显示为“那里”,应用程序不再将其列在其字体列表中(我专门尝试了写字板,在删除 webdings.ttf 之前和之后 - 无需重新启动)是
的,我知道 - 重新启动是一个糟糕的解决方案 - 特别是如果您需要更新字体,因为您无法重新安装它(无论如何通过控制面板 - 它声称字体仍然安装),直到您删除它后重新启动(我尝试过)。
但是,如果您只想删除字体 - 这不是最糟糕的解决方案 - 卸载后字体基本上消失了(应用程序看不到它,它仅在控制面板字体中可见据我所知)并且您不需要强制重新启动。
来自 RemoveFontResourceFont 上的 SDK 帮助(可能会指出为什么会出现奇怪的现象)
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.
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)
一旦找到 Havenard 提到的实际文件名并使用您提到的文章,您就可以执行以下操作,
其中 FontFilePath 是要删除的文件的文件路径。
更多信息在这里:
technet 文章
您可能遇到的问题,在看到您的评论之前我没有想到的是,程序可能需要某种特定项目的字体。所有已知的系统字体都存储在注册表中。如果删除字体,您还应该从注册表中删除该密钥。注册表路径如下
按键如下:
Once you find the actual filename as Havenard mentioned and using the article you mentioned you can do a
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
The keys are as followed:
您的所有字体都可以在 C:\WINDOWS\Fonts\ 中找到,
资源管理器将屏蔽此文件夹以显示字体名称而不是真实的文件名,但它全部都在那里。您可以编辑并注释掉 C:\WINDOWS\Fonts\desktop.ini 中的行来禁用此功能并显示字体文件(可能需要重新打开资源管理器才能生效)。
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).