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

Re: install font function by Franz

Franz
Thu May 01 18:15:13 CDT 2008

baphensley wrote:

> The function below seems to adequately install fonts from a .vbs on
> Win2K.

I do not have time for testing ATM, but I found your question interesting
and I
googled for the problem: maybe this can be an interesting hint:

<http://www.visualbasicscript.com/m_2176/mpage_1/key_/tm.htm#2176>

it uses an VB6 API approach, I think it can be translated to WSH
and hopefully it will works for all NT based OSs.



Re: install font function by Gottfried

Gottfried
Fri May 02 04:16:26 CDT 2008

baphensley wrote:
> 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
>
> -----------
>
> <snip script>


Hi baphensley,

I wrote a Font install script some time ago.
It does work on XP,2003, you have to try if it works in Win2k (though in
my opinion it will work)

Take a look at this:
http://www.faq-o-matic.net/2007/06/12/schriftarten-per-skript-installieren/

The description is in german, the translation is this:

[ begin translation ]
To install new Fonts manually in Windows, you just have to drag and drop
the *.ttf fonts to the Windows Fonts folder. When you automate this
process you will notice that just copying the file does not work. The
*.ttf file will not show up in your fonts list.

The copy process of the script does work differently than the drag and
drop in the explorer. The following script automates windows explorer to
do the copying, so the font is correctly installed. The script also
checks if the fonts file is already installed in the system to prevent
messages like "the font is already installed on this system..." .

Place the font files to install (*.ttf/*.fon) in a Folder
"FontsToInstall" next to the script, then just start the script (it will
work as a logon script, but only for administrators and users with
permissions to install fonts) and the missing fonts will be installed.

Important: All files in the FontsToInstall folder will be installed, so
make sure that it only contains valid font files! Tested with Windows XP
SP2 german.
[ end translation ]

You can easily change your script to use the "Shell.Application" Object
(oApp in my script) to copy the font file. The script waits for the copy
(and install) action to finish, so you will not have to make a
wscript.sleep call in your script.
Also the fonts control panel will not show up with this script, although
you might see the progress bar of the fonts installation routine of
explorer (also visible when dragging and dropping new font files into
the folder)

I think your approach is working perfectly well and this procedure will
work also in the newer operating systems (until MS decides to change the
drag and drop behavior in explorer)


HTH
Gottfried

Re: install font function by Alex

Alex
Tue May 06 08:31:05 CDT 2008

Here's a simpler way to do it using the Shell32 COM library without
requiring sendkeys use or having the Fonts folder flash; I think it may
force a desktop refresh sometimes, but that's a distinct issue - and this is
much more direct and reliable anyway.

Set sa = CreateObject("Shell.Application")
Set fonts = sa.NameSpace(&H14)
fonts.CopyHere("D:\Dsp\Windows Fonts\Reflex - Black.ttf")

&H14 is the hex id for the Fonts folder, universal across Windows versions.
You'll want to use the full path to the font file for reliability.

"baphensley" <BAPHensley@gmail.com> wrote in message
news:a152cb63-3bb2-40b8-a970-7a1592de6c69@m3g2000hsc.googlegroups.com...
> 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


Re: install font function by baphensley

baphensley
Mon May 12 17:31:11 CDT 2008

On May 1, 4:15=A0pm, "Franz aRTiglio" <franz...@N0SPAMtin.it> wrote:
> baphensleywrote:
> > The function below seems to adequately install fonts from a .vbs on
> > Win2K.
>
> I do not have time for testing ATM, but I found your question interesting
> and I
> googled for the problem: maybe this can be an interesting hint:
>
> <http://www.visualbasicscript.com/m_2176/mpage_1/key_/tm.htm#2176>
>
> it uses an VB6 API approach, I think it can be translated to WSH
> and hopefully it will works for all NT based OSs.

Franz,

Thanks, I saw that post, but was unable to get the broadcast to work.

Bruce

Re: install font function by baphensley

baphensley
Mon May 12 17:38:00 CDT 2008

Gottfried and Alex,

Thanks for the suggestion to use Shell.Application.CopyHere.

I had seen this approach, and tried it.

Unfortunately, it only seemed to complete registering the font about
1/4 of the time, even with no changes to the code.

Bruce


Re: install font function by Alex

Alex
Tue May 13 03:24:25 CDT 2008

Can you characterize the situations when it doesn't appear to work?

If you could, show us how you're using the code, and tell us what OS you're
running it on; whether the installed fonts have the same file names as
existing fonts; and whether you're doing a reboot after the fonts are
installed. Also, check the script and make sure you do NOT have an On Error
Resume Next statement active; that will quietly suppress errors so there's
no chance of seeing the real problem.

Because of your description of it working about a quarter of the time, I'm
suspicious of it being a problem with some specific files or an issue with
font collection refresh being slow.

"baphensley" <BAPHensley@gmail.com> wrote in message
news:e6210da9-ae3b-437f-8364-3ce552ebd048@b1g2000hsg.googlegroups.com...
> Gottfried and Alex,
>
> Thanks for the suggestion to use Shell.Application.CopyHere.
>
> I had seen this approach, and tried it.
>
> Unfortunately, it only seemed to complete registering the font about
> 1/4 of the time, even with no changes to the code.
>
> Bruce
>

Re: install font function by baphensley

baphensley
Tue May 13 10:54:30 CDT 2008

On Win2K today ... XP in a few months.

No On Errors statements.

No reboot ... the goal is an install that is available immediately,
without user intervention, and immediately "advertised" to running
applications.

The function is called from a script that has a constant that defines
the one function argument, so it always installs the same font.

The "statistic" is from the following test on a single computer ...

- run script to install font
- check Acrobat and Word to see if it is installed
- uninstall from Fonts control panel
- close control panel
- repeat all above steps again, and again, and again, ...

So, there is nothing I can imagine that is different with each run.

If I perform the test above with the script I posted, it works 100
percent. If I perform it after adapting to use CopyHere, it works
about 25 percent, randomly.

Re: install font function by Alex

Alex
Tue May 13 13:51:21 CDT 2008

I'm going to give this a try with a handful of fonts at once, probably
tomorrow morning when I can try a 2000 desktop. Can you confirm whether the
font file actually does get copied, but just fails to show up? If you don't
have time, don't worry about it since I can check that during my 2k test
tomorrow.

Given what you've described, I suspect the problem is with how Windows 2000
in particular handles some Shell.Application calls; I suspect it just queues
up a request, and then the script terminates before it has been done.
Another possibility is spotty behavior with the CopyHere functionality
triggering font install on Win2k.

If it's the first issue - the script terminating quickly - inserting a
WScript.Sleep 1000
statement would be likely to "fix" it, although it's an ugly hack. If it's
the CopyHere functionality, it's possible that invoking the font file's
Install option via Shell.Application would solve it. I'll check both
scenarios.

"baphensley" <BAPHensley@gmail.com> wrote in message
news:d9713339-2a42-47a1-8a7c-acb463f7e151@i76g2000hsf.googlegroups.com...
> On Win2K today ... XP in a few months.
>
> No On Errors statements.
>
> No reboot ... the goal is an install that is available immediately,
> without user intervention, and immediately "advertised" to running
> applications.
>
> The function is called from a script that has a constant that defines
> the one function argument, so it always installs the same font.
>
> The "statistic" is from the following test on a single computer ...
>
> - run script to install font
> - check Acrobat and Word to see if it is installed
> - uninstall from Fonts control panel
> - close control panel
> - repeat all above steps again, and again, and again, ...
>
> So, there is nothing I can imagine that is different with each run.
>
> If I perform the test above with the script I posted, it works 100
> percent. If I perform it after adapting to use CopyHere, it works
> about 25 percent, randomly.


Re: install font function by baphensley

baphensley
Tue May 13 14:36:12 CDT 2008

On May 13, 11:51=A0am, "Alex K. Angelopoulos" <aka(at)mvps.org> wrote:
> I'm going to give this a try with a handful of fonts at once, probably
> tomorrow morning when I can try a 2000 desktop. Can you confirm whether th=
e
> font file actually does get copied, but just fails to show up? If you don'=
t
> have time, don't worry about it since I can check that during my 2k test
> tomorrow.
>
> Given what you've described, I suspect the problem is with how Windows 200=
0
> in particular handles some Shell.Application calls; I suspect it just queu=
es
> up a request, and then the script terminates before it has been done.
> Another possibility is spotty behavior with the CopyHere functionality
> triggering font install on Win2k.
>
> If it's the first issue - the script terminating quickly - inserting a
> WScript.Sleep 1000
> statement would be likely to "fix" it, although it's an ugly hack. =A0If i=
t's
> the CopyHere functionality, it's possible that invoking the font file's
> Install option via Shell.Application would solve it. I'll check both
> scenarios.
>
> "baphensley" <BAPHens...@gmail.com> wrote in message
>
> news:d9713339-2a42-47a1-8a7c-acb463f7e151@i76g2000hsf.googlegroups.com...
>
>

Yes, the font is copied ... if I run the test using CopyHere and it
"fails", and I'm looking at my test PDF in Acrobat with the missing
font characters, and then I open the Fonts control panel to see if it
is there, the PDF displayed in Acrobat immediately updates to show the
font characters before I can scroll through the list of fonts to
confirm it's there! This is what prompted me to display the control
panel in order to complete the install.

As you see, my alternate approach, accomplished by temporarily opening
the Fonts control panel, also requires a pause with WScript.Sleep to
be successful, so it's no loss to do it with the CopyHere. I'll try it
with the added pause.

Re: install font function by baphensley

baphensley
Tue May 13 14:45:11 CDT 2008

On May 13, 11:51=A0am, "Alex K. Angelopoulos" <aka(at)mvps.org> wrote:
> I'm going to give this a try with a handful of fonts at once, probably
> tomorrow morning when I can try a 2000 desktop. Can you confirm whether th=
e
> font file actually does get copied, but just fails to show up? If you don'=
t
> have time, don't worry about it since I can check that during my 2k test
> tomorrow.
>
> Given what you've described, I suspect the problem is with how Windows 200=
0
> in particular handles some Shell.Application calls; I suspect it just queu=
es
> up a request, and then the script terminates before it has been done.
> Another possibility is spotty behavior with the CopyHere functionality
> triggering font install on Win2k.
>
> If it's the first issue - the script terminating quickly - inserting a
> WScript.Sleep 1000
> statement would be likely to "fix" it, although it's an ugly hack. =A0If i=
t's
> the CopyHere functionality, it's possible that invoking the font file's
> Install option via Shell.Application would solve it. I'll check both
> scenarios.
>
> "baphensley" <BAPHens...@gmail.com> wrote in message
>
> news:d9713339-2a42-47a1-8a7c-acb463f7e151@i76g2000hsf.googlegroups.com...

I tried it with a pause, again without success. Here is the code ...
in case I made some other mistake. Once again, just opening the Fonts
folder after running this script completes the install.

'Initialization
const FONT_LIST =3D "\\myserver\tools\Fonts\Code128JK\C8______.PFM|\
\myserver\tools\Fonts\Code128JK\C8______.PFB"

'Main
installFonts(FONT_LIST)

function installFonts(fontList)
'Install fonts from a list of font file fullpaths separated by
vertical bars

installFonts =3D False

dim FontsSpecialFolder
FontsSpecialFolder =3D
createobject("WScript.Shell").SpecialFolders("Fonts")

dim sa
set sa =3D CreateObject("Shell.Application")

dim oFolder
set oFolder =3D sa.Namespace(&H14)

dim fso
set fso =3D createobject("Scripting.FileSystemObject")

for each fontFile in split(fontList,"|")
if not fso.FileExists(FontsSpecialFolder & "\" &
mid(fontFile,InStrRev(fontFile,"\")+1)) then
oFolder.CopyHere fontFile
WScript.Sleep 1000
installFonts =3D True
end if
next

end function

Re: install font function by baphensley

baphensley
Tue May 13 22:39:13 CDT 2008

The following code seems to have solved my problem. More testing will,
hopefully, confirm this.

The script would not successfully install the font if the Fonts folder
was already open when the file copying occurred, so I added code to
close the Fonts folder before the copy.

I switched to wscript.shell.run to temporarily open the Fonts folder.
This allowed it to open hidden.

With this new code, the Sleep statement does not seem to be needed.

Thanks to all who helped.

Bruce

'--------
function installFonts(fontList)
'Install fonts from a list of font file fullpaths separated by
vertical bars
installFonts = False

dim wss
set wss = createobject("WScript.Shell")

dim fso
set fso = createobject("Scripting.FileSystemObject")

dim sa
set sa = createobject("Shell.Application")

dim window

'Close the Fonts folder if it's open
for each window in sa.windows
if window.LocationURL = "file:///" &
replace(wss.SpecialFolders("Fonts"),"\","/") then window.quit
next

'Copy the fonts
dim fontFile
for each fontFile in split(fontList,"|")
if not fso.FileExists(wss.SpecialFolders("Fonts") & "\" &
mid(fontFile,InStrRev(fontFile,"\")+1)) then
fso.CopyFile fontFile,wss.SpecialFolders("Fonts") & "\"
installFonts = True
end if
next

'If fonts were copied, complete the install
if installFonts then

'Open the Fonts folder to complete install
wss.run wss.SpecialFolders("Fonts"),0

'Close the Fonts folder
for each window in sa.windows
if window.LocationURL = "file:///" &
replace(wss.SpecialFolders("Fonts"),"\","/") then window.quit
next
end if
end function

Re: install font function by Alex

Alex
Wed May 14 07:28:53 CDT 2008

Bruce,

You did some impressive detail-oriented problem-solving in this process.

I think the most we did was toss the ball back to you a few times when it
landed near us. ;)

"baphensley" <BAPHensley@gmail.com> wrote in message
news:4917eb8e-8b38-4226-8b24-fd5f72e27e28@f63g2000hsf.googlegroups.com...
> The following code seems to have solved my problem. More testing will,
> hopefully, confirm this.
>
> The script would not successfully install the font if the Fonts folder
> was already open when the file copying occurred, so I added code to
> close the Fonts folder before the copy.
>
> I switched to wscript.shell.run to temporarily open the Fonts folder.
> This allowed it to open hidden.
>
> With this new code, the Sleep statement does not seem to be needed.
>
> Thanks to all who helped.
>
> Bruce
>
> '--------
> function installFonts(fontList)
> 'Install fonts from a list of font file fullpaths separated by
> vertical bars
> installFonts = False
>
> dim wss
> set wss = createobject("WScript.Shell")
>
> dim fso
> set fso = createobject("Scripting.FileSystemObject")
>
> dim sa
> set sa = createobject("Shell.Application")
>
> dim window
>
> 'Close the Fonts folder if it's open
> for each window in sa.windows
> if window.LocationURL = "file:///" &
> replace(wss.SpecialFolders("Fonts"),"\","/") then window.quit
> next
>
> 'Copy the fonts
> dim fontFile
> for each fontFile in split(fontList,"|")
> if not fso.FileExists(wss.SpecialFolders("Fonts") & "\" &
> mid(fontFile,InStrRev(fontFile,"\")+1)) then
> fso.CopyFile fontFile,wss.SpecialFolders("Fonts") & "\"
> installFonts = True
> end if
> next
>
> 'If fonts were copied, complete the install
> if installFonts then
>
> 'Open the Fonts folder to complete install
> wss.run wss.SpecialFolders("Fonts"),0
>
> 'Close the Fonts folder
> for each window in sa.windows
> if window.LocationURL = "file:///" &
> replace(wss.SpecialFolders("Fonts"),"\","/") then window.quit
> next
> end if
> end function