Install Font

//Install Font
Install Font 2015-10-28T21:14:10+00:00

The Toolkit Forums General Install Font

  • Author
    Posts
  • Treeman
    Participant
    Post count: 2
    #791 |

    Does anyone know how to install a .TTF font file?

  • Treeman
    Participant
    Post count: 2

    I was able to get this installed with this command:

    $FONTS = 0x14
    $objShell = New-Object -ComObject Shell.Application
    $objFolder = $objShell.Namespace($FONTS)
    $objFolder.CopyHere(“$dirFiles\3OF9___0.TTF”)

  • Martureo
    Participant
    Post count: 5

    Hi Gang,

    Thought i would recreate this thread as it pertains to both the install and uninstall of multiple font files via Shell ComObject Method.

    CONS : however there has been known issues where using Shell methods like this, fail to work on Remote and Build Agents because SHELL is not accessable when using those agents to execute your powershell script at : Avoid Using SHELL when using Remote or Build Agents

    I hope this code helps – I obtained the majority of this code at : Install Fonts via Command Line

    <code>
    ## Add or Remove Font Files - only tested with TTF font files thus far
        #&lt;#
        #=======================================================================================================
        # ADD or REMOVE MULTIPLE FONT FILES [Using ComObjects]
        #=======================================================================================================
        # This code will install or uninstall a font using ComObject
        # You Must Modify the following variables in order to work
        # (A) $dirFiles                ==&gt;  This is the source folder path that contains all of your font files
        # (B) $InstallOrUninstall      ==&gt;  $true = Install Font ...  $false = UnInstall Font
        #=======================================================================================================
            # Define Working Variables
                #$dirFiles = &quot;C:\Temp\Fonts&quot;
                $InstallOrUninstall = $true  # $true = Install  ...or...  $false = UnInstall
                $srcFontFiles = Get-ChildItem &quot;$($dirFiles)\Fonts&quot;
                $Fonts = (New-Object -ComObject Shell.Application).Namespace(0x14)
            # Copy each file into the Font Folder or Delete it - Depends on the $InstallOrUninstall variable setting
                ForEach($srcFontFile in $srcFontFiles) 
                {
                    $srcFontFileName = $srcFontFile.name
                    $srcFontFileFullPath = $srcFontFile.fullname
                    $targFonts = &quot;C:\Windows\Fonts\$($srcFontFileName)&quot;
                    If ((Test-Path $targFonts -PathType any) -and ($InstallOrUninstall -eq $false)) { Remove-Item $targFonts -Recurse -Force } # UnInstall Font
                    If ((-not(Test-Path $targFonts -PathType container)) -and ($InstallOrUninstall -eq $true)) { $fonts.CopyHere($srcFontFileFullPath, 16) } # Install Font
                }
        #&gt;
    </code>
    • This reply was modified 4 weeks, 1 day ago by  Martureo.

You must be logged in to reply to this topic.