• 0

[VB] Help copying/installing fonts via command line


Question

I need for users to be able to install fonts to their system without admin privileges at work. We have a system set up that installs software from a defined database that runs as SYSTEM, and that is working well so far.

I had thought that copying font files to the WINDOWS\Fonts directory would be enough to install them, but apparently it is not.

So I found a VB script that copies .ttf files to the Fonts directory using the Windows shell, causing the font to be properly registered. This runs at system startup as SYSTEM, so it has write permission to the directory. All they have to do is copy their new fonts to a directory on the file server and restart their system.

on error resume next
Const FONTS = &H14
dim oFSO, oShell, oFolder1, oFolder2, sRoot
sRoot="\\fileserver\Shared\company\fonts"
Set oShell = CreateObject("Shell.Application")
set oFSO=createobject("scripting.filesystemobject")
Set oFolder1 = oShell.Namespace(FONTS)
set oFolder2 = oFSO.getfolder(sRoot)
for each oFile in oFolder2.files
    sName=lcase(oFile.name)
    if right(sName,4)=".ttf" then
      if not ofso.fileexists(oFolder1.self.path & "\" & sName) then
        oFolder1.copyhere sRoot & "\" & sName
      end if
    end if
next
on error goto 0

The problem is that this only copies files to the local system if they do not already exist there. I had been using robocopy to copy them over, but that wasn't registering them.

So now what I need to do is to figure out how to copy over fonts that are not correctly registered in HKLM\Software\Microsoft\Windows NT\Fonts

Alternatively, I need to be able to automatically delete .ttf files from the local system that are not correctly registered in that same registry key. I definitely don't want to go through the 1,500+ fonts manually.

I also need to be able to copy over .ttf, .otf, .fon and any other font extensions that are possible.

I don't know anything about VB script. Can someone explain how to make that go or write up something that would do that?

6 answers to this question

Recommended Posts

  • 0

Does anyone know of another forum where other experts may be able to assist if nobody here knows? Anyone have a friend who might know the answer? Google's not much help except to teach me VB from scratch, which I'm not really up for just to do this one thing.

  • 0

hi,

the issue here is that putting fonts in the correct folder is not enough to make them work. they need to be registered with the windows registry...

when you double click (or drag) a font into the folder this act registers it with the system..

so, you have two options really..

1. is to execute a registry patch to manually register the font for use

2. reboot the system which i believe will force them to be registered

i think registry patch would be the best way to go... good luck! :)

  • 0

This copies them correctly so that they get registered. This is already doing what needs to be done.

But...

I had copied them wrong in the past using robocopy, so now there are lots of fonts in their Fonts folders that are not correctly registered.

Is there a VB way to view a list from the registry of the fonts that are installed, then skip those when copying fonts over to the computer?

for each regfontname in regkey

if (fontname == regfontname)

continue

else

copy font

or something like that?

(FYI: rebooting doesn't do it. If it did, that would be great, but it doesn't. It has to be copied using the shell, either drag and drop, or using something like this script.)

  • 0

Alternative that we're going to try:

we're going to comment out the 'if not ofso.fileexists' line (and its corresponding end if) and run that. That should hopefully we think maybe copy over all of the fonts whether they need to be copied or not.

Once that has run on each computer, we can uncomment those lines again so that it only installs new fonts when it runs in the future instead of trying to install all 1700 again.

[edit]

Fail.

If the font is already registered, the copy process comes up with an error message. I'm not going to sit and click OK 1,000+ times.

Other thoughts? How can we compare against the registry?

[/edit]

The question remains though:

how can I include more than one file extension? What's the VB command for "or"?

if right(sName,4)=".ttf" or ".otf" or ".fon" then

  • 0
  Quote

how can I include more than one file extension? What's the VB command for "or"?

if right(sName,4)=".ttf" or ".otf" or ".fon" then

 If Right(sName,4) = ".ttf" Or  Right(sName,4) = ".otf"  Or  Right(sName,4) = ".fon" Then
 '-> Your Code Here
 End If

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.