在 Windows XP 中安装字体的脚本

Script to Install Font in Windows XP

我正在尝试使用 VBScript 在 windows XP 中安装字体。但出于某种原因,我的脚本在 Windows 7 中运行良好,但在 Windows XP 中不起作用。我需要在不重启系统的情况下安装字体,所以我不得不选择这种方法,而不是其他需要重启系统的注册表更改方法。这是我的 VBScript

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("D:\Logs\")
Set objFolderItem = objFolder.ParseName("Roboto-Italic.ttf")
objFolderItem.InvokeVerb("Install")

我猜 InvokeVerb("Install") 命令在 Windows XP 中不起作用。在那种情况下,还有其他选择吗?请指导我谢谢...

下一个脚本(代码片段)应该适用于(过时的)Windows XP:

Const ssfFONTS = &H14&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(ssfFONTS)
objFolder.CopyHere "D:\Logs\Roboto-Italic.ttf"

如果字体已经安装,系统可能会提示您覆盖它。不确定使用上述方法是否需要重新启动...

ShellSpecialFolderConstants enumeration

Specifies unique, system-independent values that identify special folders. These folders are frequently used by applications but which may not have the same name or location on any given system.

其中:

  • ssfFONTS 0x14 (20). Virtual folder that contains installed fonts. A typical path is C:\Windows\Fonts.

阅读Hey, Scripting Guy! How Can I Install Fonts Using a Script?:

As soon as the font has been added to the folder, the operating system will immediately install the font for you...
That’s true, but with one very important caveat: you must copy the file using the Shell object. Admittedly, you can use WMI or the FileSystemObject to copy a file into the Fonts folder; however, when you do so the operating system will not automatically install the font for you. As far as we know, the only programmatic way to get Windows to recognize that a new font has been added to the Fonts folder, and thus get Windows to install that font for you, is to use the Shell object.