CopyHere not working as expected when copying fonts

Deadly 提交于 2021-01-20 12:09:05

问题


I made a script, which is supposed to copy a bunch of fonts to the Windows font folder. When I run it, I receive the output of the file names I would like copied, but nothing copies. It works when I remove the For loop, and specify file names. Any help appreciated.

Const FONTS = &H14&
sFolder = "c:\FontInstalls\"
Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.Namespace(FONTS) 
Set objFSO = CreateObject("Scripting.FileSystemObject")

For Each oFile In objFSO.GetFolder(sFolder).Files
  If UCase(objFSO.GetExtensionName(oFile.Name)) = "TTF" Then
    objFolder.CopyHere(oFile)
    wscript.echo(oFile)
  End if
Next

回答1:


Fonts need to be installed not copied. Copy the shell's objects rather than underlying files. The shell installs fonts copied into the fonts folder.

Here's the objects you need adding files to a zip.

Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")

Set SrcFldr=objShell.NameSpace(Ag(1))
Set DestFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Msgbox "Finished"


来源:https://stackoverflow.com/questions/23094743/copyhere-not-working-as-expected-when-copying-fonts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!