为何Windows 2018年新增的非管理员用户字体目录未被纳入KnownFolder API?
Great question—this is actually an intentional design choice rather than an oversight, and there are a few key reasons behind Microsoft’s decision:
KnownFolder's core purpose
The KnownFolder API is built to expose standardized, system/user-wide directories with stable, well-defined semantics—think Documents, Downloads, or Program Files. The non-admin font folder (%LOCALAPPDATA%\Microsoft\Windows\Fonts) is a specialized, sandboxed location tied directly to Windows’ font management subsystem. It’s not meant to be a general-purpose storage path for apps to reference directly; its sole job is to hold fonts installed by non-privileged users without requiring admin rights.Font system design constraints
Unlike admin-installed fonts (which get registered in the system-wideHKLMregistry), non-admin fonts are only visible to the user who installed them. Windows doesn’t expose this folder via KnownFolder because it expects apps to access these fonts through GDI or DirectWrite’s font enumeration APIs, not by reading the directory path directly. This abstraction lets Microsoft adjust the underlying storage implementation in future updates without breaking apps.Backward compatibility priorities
KnownFolder GUIDs are intentionally kept stable to avoid breaking existing applications that rely on the API’s fixed list of folders. Adding this specialized font directory would introduce a new dependency that older apps wouldn’t recognize, and since there’s a supported alternative (using font enumeration APIs), Microsoft didn’t see value in expanding the KnownFolder list for this use case.
Practical Workaround for Your Library
If you need to retrieve this path for your storage/retrieval functionality, you’ll have to construct it manually using environment variables. Here’s an example in C#:
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\Windows\Fonts")
Just note that this path is an implementation detail, not an official API contract—add error handling to account for potential changes in future Windows versions.
内容的提问来源于stack exchange,提问作者soc

