Font Auto Install

I like automating things. I don’t like repeating the same task over and over again. So when I a user from the design department started logging a new ticket every week to have new fonts installed I decided it was time to make life a little easier for both of us.

The easy option would be to just give her local admin rights so she could install the fonts herself, but that’s a silly idea for obvious reasons. Instead I went with a powershell script to install them automatically.

My first thought was to have a login script that would install any font files that the user places in a given folder. I quickly gave up on the login script idea, it was just too difficult to get the permissions sorted.

I did stick with the plan to have the user drop font files into a folder and have the script install from there, but instead I chose to setup a scheduled task to run my script every 5 mins. If there’s a font file in the folder when the script runs it will be installed and the file deleted.

The only catch is that the user has to log off and back on again to actually be able to see the font, but that’s a small price to pay when it saves a call to helpdesk and having to wait for someone to respond to the request.

###########################################################################
#  Script Name  : FontInstall.ps1
#  Author       : Chris Dwyer
#  Date         : 01/02/2019
#  Last Edited  : 01/02/2019
#  Description  : Install fonts from a shared directory
###########################################################################
# Purpose:
# - Install fonts for a user without granting admin rights
# Method:
# - User places .oft or .ttf files in a folder on a network share 
# - Run this script as a scheduled task every 5 mins during business hours
# Notes:
# 
###########################################################################


$fontFolder = "\ServerPublicGraphic DesignTypeInstall"

$objShell = New-Object -ComObject Shell.Application
$Fonts =  $objShell.NameSpace(0x14)
$FOF_SILENT_FLAG = 4
$FOF_NOCONFIRMATION_FLAG = 16

if(!(Test-Path $fontFolder))
{
    Write-Warning "$fontFolder - Not Found" 
}
else
{
    $objFolder = $objShell.namespace($fontFolder)

        Try{
            foreach ($file in $objFolder.items())
            {
                $fileType = $($objFolder.getDetailsOf($file, 2))
                if(($fileType -eq "OpenType font file") -or ($fileType -eq "TrueType font file"))
                {
                    $Fonts.CopyHere($File.Path, $FOF_SILENT_FLAG + $FOF_NOCONFIRMATION_FLAG)
                    Remove-Item $File.Path
                }
            }
        }
        catch{
            Write-Warning "Font Install Failed"
        }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s