这是我的脚本 如何从 Windows 命令提示符安装字体?
Dim WinFontDir
Dim SrcFontDir
WinFontDir = "C:\Windows\Fonts"
SrcFontDir = "..\fonts.test"
Set objShell = CreateObject("Shell.Application")
Set objFontFolder = objShell.Namespace(WinFontDir)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSrc = objFSO.GetFolder(SrcFontDir)
Set colFiles = objSrc.Files
For each objFile in colFiles
If objFSO.FileExists(WInFontDir + "\" + objFile.Name) Then
WScript.Echo objFile.Name
else
WScript.Echo "Copying " + objFile.Name
objFSO.CopyFile SrcFontDir + "\" + objFile.Name, WinFontDir + "\" + objFile.Name
Set objFolderItem = objFontFolder.ParseName(objFile.Name)
objFolderItem.InvokeVerb("Install") // <- exception
End If
Next
基本上,我希望能够遍历字体文件夹,并且仅当字体文件不存在于“C:\Windows\Fonts”中时才复制和安装。
但是当谈到这一行时objFolderItem.InvokeVerb("Install")
我收到了这个错误信息:
所需对象:'objFolderItem'
原因何在?
答案1
最后,只有这种方法对我有用:
Dim WinFontDir
Dim SrcFontDir
WinFontDir = "C:\Windows\Fonts"
SrcFontDir = "..\fonts"
Set objShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSrc = objFSO.GetFolder(SrcFontDir)
Set colFiles = objSrc.Files
For each objFile in colFiles
If Not objFSO.FileExists(WInFontDir + "\" + objFile.Name) Then
WScript.Echo "Copying " + objFile.Name
FONTS = &H14&
Set objFontFolder = objShell.Namespace(FONTS)
objFontFolder.CopyHere objFile.Path
End
Next
注意:仅复制字体文件夹中不存在的文件