• 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

    • As it would on any other tech website whether it be Windows, Apple, etc. I wouldn’t expect it any other way.
    • Mozilla should shut down everything except the browser and the services they whitelabel (for example Firefox VPN from Mullvad). Everything else just cost them money and have never returned any revenue. Focusing in the browser is what makes sense considering what is going to change regarding their income sources. About Firefox and chromium... if they ever have to abandon Gecko because of financial issues it is more likely to use Apple's WebKit and not Chromium and Blink. WebKit is more versatile for Firefox because it will allow them even to keep Firefox's extension ecosystem. The same way GNOME Web which is a WebKit browser has experimental Firefox extension support.
    • I really dont like how they’ve put shadows under window elements making the sidebar and toolbar buttons look like they sit above the window itself. Looks very odd and clunky.
    • Rubbish. It's chock-full of ads and with manifest 3.0,the gloves are off. Google does not even pretend now. They want évil and want your data
    • Glary Utilities 6.27.0.31 by Razvan Serea Glary Utilities offers numerous powerful and easy-to-use system tools and utilities to fix, speed up, maintain and protect your PC. Glary Utilities allow you to clean common system junk files, as well as invalid registry entries and Internet traces. You can manage and delete browser add-ons, analyze disk space usage and find duplicate files. You can also view and manage installed shell extensions, encrypt your files from unauthorized access and use, split large files into smaller manageable files and then rejoin them. Furthermore, Glary Utilities includes the options to find, fix, or remove broken Windows shortcuts, manage the programs that start at Windows startup and uninstall software. All Glary Utilities tools can be accessed through an eye-pleasing and totally simplistic interface. Glary Utilities 6.27.0.31 changelog: Optimized Disk Cleaner: Optimized the scanning algorithm for Firefox to enhance user experience. Optimized Disk Cleaner: Added support for Nitro Pro 14. Optimized Tracks Eraser: Optimized the scanning algorithm for Firefox to enhance user experience. Optimized Tracks Eraser: Added support for Nitro Pro 14. Optimized Startup Manager: Optimized the review algorithm to enhance user experience. Optimized Uninstaller Manager: Optimized the scanning algorithm to enhance user experience. Minor GUI improvements. Minor bug fixes. Download: Glary Utilities 6.27.0.31 | 27.0 MB (Freeware) Download: Portable Glary Utilities | 32.3 MB View: Glary Utilities Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      Æhund earned a badge
      One Month Later
    • One Month Later
      CoolRaoul earned a badge
      One Month Later
    • First Post
      Kurotama earned a badge
      First Post
    • Collaborator
      Carltonbar earned a badge
      Collaborator
    • Explorer
      MusicLover2112 went up a rank
      Explorer
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      ATLien_0
      269
    3. 3
      +FloatingFatMan
      242
    4. 4
      +Edouard
      202
    5. 5
      snowy owl
      168
  • Tell a friend

    Love Neowin? Tell a friend!