The function below seems to adequately install fonts from a .vbs on
Win2K.
I would appreciate advice on the following ...
- The Fonts control panel flashes briefly. How could I make this less
obtrusive or invisible?
- The pause (wscript.sleep) allows the applet time to complete it's
magical install steps. Can this be replaced with more robust steps
that wait just until it's tasks complete?
- We will be moving to WinXP in a few months. Is this approach likely
to work under XP? If not, is there an alternative that would work
under both OSs?
- Am I all wet? Is there a more robust approach?
Thanks,
Bruce
-----------
function installFonts(fontList)
'Install fonts from a list of font file fullpaths separated by
vertical bars
'
' Returns True if at least 1 font was installed.
installFonts = False
dim FontsSpecialFolder
FontsSpecialFolder =
createobject("WScript.Shell").SpecialFolders("Fonts")
'Copy the fonts
dim fso
set fso = createobject("Scripting.FileSystemObject")
for each fontFile in split(fontList,"|")
if not fso.FileExists(FontsSpecialFolder & "\" &
mid(fontFile,InStrRev(fontFile,"\")+1)) then
fso.CopyFile fontFile,FontsSpecialFolder & "\"
installFonts = True
end if
next
'Allow Windows to complete the install if at least one file was
copied
dim sa
set sa = CreateObject("Shell.Application")
if installFonts then
'Open the Fonts control panel
dim item
for each item in sa.NameSpace(3).Items
if item.Name = "Fonts" then item.InvokeVerb
Next
'Pause for control panel app to finish
wscript.sleep 500
'Close the Fonts control panel
dim windows
set windows = sa.Windows
for each window in windows
if window.LocationURL = "file:///" &
replace(FontsSpecialFolder,"\","/") then window.quit
next
end if
end function