• 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.
  • Posts

    • Sounds creepy to say the least. Don't need nor want AI having access to my history. They're claiming it to be an "offline" model now, but how can we guarantee they don't go behind our backs and change that?
    • Exactly! Without those fundamentals you've mentioned, Democracy is literally just Demonstration of Crazy, nothing to be proud of in such system.
    • Still I see almost no ads in mobile Edge unlike Chrome. So their browser is much better at blocking ads than Chrome and it is a fact. It even blocks ads on YouTube and you can add simple custom block filters. Also, Edge still support manifest v2 on desktop, so I'll look for another browser when I start seeing ads again.
    • Considering they consistently release a new version every year, I think it makes perfect sense. There is a minor pain point at the time of the change, so as long as they only change it once, we get over it and end up in a better place. The issue with MS' naming scheme is that they change their mind so frequently. 3.1, 95, 98, ME, 2000, XP, Vista, 7, 8, 8.1 10, there is no consistency. That was the issue, not the choice of naming the OS after the year. Minor correction: Windows 7 was 6.1. Even Windows 10 was version 6.4 at launch, but they retroactively changed it to 10.0 early on, along with an announcement that they would no longer track the kerel version and OS version separately...then proceeded to call Windows 11 version 10.0.2, so yeah, MS sucks at naming.
    • I don't think there is any problem with the two-digit number. Even if someone didn't understand the meaning, 26 > 18, so they will still understand at a glance that it is a newer version. The only downside I see is someone assuming 18 is a MUCH older than 26, but IMO, that confusion really isn't a big issue. The truth is that the majority of software companies use the 2-digit number; Microsoft is the outlier, and even they used 2-digit numbers in the past.
  • Recent Achievements

    • First Post
      viraltui earned a badge
      First Post
    • Reacting Well
      viraltui earned a badge
      Reacting Well
    • Week One Done
      LunaFerret earned a badge
      Week One Done
    • Week One Done
      Ricky Chan earned a badge
      Week One Done
    • Week One Done
      maimutza earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      481
    2. 2
      +FloatingFatMan
      264
    3. 3
      snowy owl
      238
    4. 4
      ATLien_0
      230
    5. 5
      Edouard
      176
  • Tell a friend

    Love Neowin? Tell a friend!