Installing fonts with PDQD
Has anyone tried and/or found a way to push fonts to a workstation? I've tried to find a way to set group policy to allow non admin users to install fonts, but it's surprisingly complicated to do!
Since it's usually just one person here or there that needs the fonts, it would be nice to just be able to push the fonts one a per computer basis.
-
Create a script called "ADD_Fonts.cmd", from the code below, and put it in the same folder as the font files you want to be installed.
Create a new "install package" and point to the ADD_Fonts.cmd. Check "Include entire directory".
This is how I do it and it works fine here. :)@ECHO OFF
TITLE Adding Fonts..
REM Filename: ADD_Fonts.cmd
REM Script to ADD TrueType and OpenType Fonts for WindowsREM How to use:
REM Place the batch file inside the folder of the font files OR:
REM Optional Add source folder as parameter with ending backslash and dont use quotes, spaces are allowed
REM example "ADD_fonts.cmd" C:\Folder 1\Folder 2\IF NOT "%*"=="" SET SRC=%*
REM ECHO.
REM ECHO Adding Fonts..
REM ECHO.
FOR /F %%i in ('dir /b "%SRC%*.*tf"') DO CALL :FONT %%i
REM OPTIONAL REBOOT
REM shutdown -r -f -t 10 -c "Reboot required for Fonts installation"
REM ECHO.
REM ECHO Done!
REM PAUSE
EXIT:FONT
ECHO.
REM ECHO FILE=%~f1
SET FFILE=%~n1%~x1
SET FNAME=%~n1
SET FNAME=%FNAME:-= %
IF "%~x1"==".otf" SET FTYPE=(OpenType)
IF "%~x1"==".ttf" SET FTYPE=(TrueType)ECHO FILE=%FFILE%
ECHO NAME=%FNAME%
ECHO TYPE=%FTYPE%COPY /Y "%SRC%%~n1%~x1" "%SystemRoot%\Fonts\"
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "%FNAME% %FTYPE%" /t REG_SZ /d "%FFILE%" /f
GOTO :EOF -
Emil,
If I create a folder for a user and set it up as you instructed above so that the schedule runs once a day, that would allow the user to drop fonts into the folder as needed. That begs a question. Do you know what will happen when the script runs and how it will handle trying to install a font that already exists? I can set up a test machine but thought you may already know the answer. Thank you.
-
Something like this should get you close:
EDIT: Added registry bit
Function Add-Fonts{
Param(
[cmdletBinding()]
[parameter(Mandatory=$true,Position=0)]
[string]$Source
)
$dest = 'C:\Windows\Fonts' #default font location
$files = Get-ChildItem -Path $Source
$Exclude = @()
#Logic
ForEach($file in $files){
If (Test-Path "$dest\$file"){
$Exclude += $file
} #end if
Copy-Item "$source\$file" -Destination $dest -Exclude $Exclude -Force
$type = $file.Extension
If($type -eq ".otf"){
Set-Location 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts'
New-ItemProperty -Path . -Name "$($file.Name -replace ".{4}$") (OpenType)" -Type String -Value $file.name
} #end type if
ElseIf($type -eq ".ttf"){
Set-Location 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts'
New-ItemProperty -Path . -Name "$($file.Name -replace ".{4}$") (TrueType)" -Type String -Value $file.name
} #end type elseif
} #end foreach
} #end function
#Call file wtih ./Add-fonts.ps1 -Source <your source dir on the system> -
Give me just one more second. I just re-read the file and it looks like the are using reg add to inject the registry with the font, which I didn't do in my script. I will add that step, and edit my post above with the new code. I will also be creating a secondary comment here shortly with a package xml that you can save as an xml file and import into your PDQ Deploy console so your package is all setup and ready to go. You'll just have to edit the Powershell step and change 'changeme' to the actual path you create for the user to dump fonts too.
-
Here is the XML to copy/paste into a new xml file and then Import:
<?xml version="1.0" encoding="utf-8"?>
<AdminArsenal.Export Code="PDQDeploy" Name="PDQ Deploy" Version="12.1.0.7" MinimumVersion="9.0">
<Package>
<PackageDefinition name="Definition">
<CopyMode>Default</CopyMode>
<InventoryScanProfileId value="null" />
<RunAs value="null" />
<ScanAfterDeployment value="null" />
<Steps type="list">
<PowerShellStep>
<CustomCommandLine></CustomCommandLine>
<Files>\change\path\to\Add-fonts.ps1</Files>
<Script>& '.\Add-fonts.ps1' -Source "changeme"</Script>
<SuccessCodes>0</SuccessCodes>
<RunAs value="null" />
<Conditions type="list">
<PackageStepCondition>
<Architecture>Both</Architecture>
<Version>All</Version>
<TypeName>OperatingSystem</TypeName>
</PackageStepCondition>
<PackageStepCondition>
<IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
<TypeName>LoggedOnUser</TypeName>
</PackageStepCondition>
</Conditions>
<ErrorMode>StopDeploymentFail</ErrorMode>
<IsEnabled value="true" />
<Title>Copy fonts</Title>
<TypeName>PowerShell</TypeName>
</PowerShellStep>
</Steps>
<Timeout value="60" />
<UseCustomTimeout value="false" />
</PackageDefinition>
<Description></Description>
<FolderId value="null" />
<Name>Add Fonts</Name>
<Path>Add Fonts</Path>
<Version></Version>
<PackageDisplaySettings name="DisplaySettings">
<DisplayType>Normal</DisplayType>
<IconKey></IconKey>
<SortOrder value="10" />
</PackageDisplaySettings>
</Package>
</AdminArsenal.Export> -
That would be good. I sort of tested it a little bit in chunks as I went, mostly to make sure I was putting the right data together, but I didn't test it in its entirety as a script or try to deploy it. Please let me know if you get any red text from the powershell, and post it here so I can have a look and fix it.
-
Found a Alternative....
FontReg.exe
http://code.kliu.org/misc/fontreg/
You need to use fontreg.exe /copy it will install all fonts within the directory and add a reg entry. (Reboot Required)
Regards,
Pushpak
-
Pushpak,
Thanks for the alternative. If I cannot get the solution provided by Stephen to work then I will try it.
Stephen,
I copied the script, pasted to Notepad, saved it as an XML, and imported it into PDQ Deploy. I changed the source and verified the path in Step 1. When deployed it failed with the status message, "Not Found - Failed to read file on source." I went back, verified the path, and verified permissions. The Deploy User has rights to the directory and the path is correct.
Is "Add-fonts.ps1" a pre-existing utility in PDQ Deploy or on the Windows server? It seems that it is being called from \\TUSCPDQ\PDQ\Powershell, and since that does not exist on our network I am guessing that is part if not all of the issue here. Will you let me know what I need to do here?
Much appreciated.
-
You'll want to change the Files to something other than TUSCPDQ. That's the name of my development box for staging changes to my PDQ environment.
You'll want to put it wherever you find easiest to get to. For me, in DEV, that is in the folder mentioned above, but is entirely different from your environment. Use the ... button to browse for and find your copy of Add-fonts.ps1. The field will update itself accordingly.
-
Here is my font script for PDQ. It works great for Windows 10 & 7. I have a schedule set to install on any machines found in an AD group. The helpdesk then just has to add the machine in the group.
- Copy fonts to C:\windows\fonts
- command prompt -
@ECHO OFF
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Solitas Normal Book (OpenType)" /t REG_SZ /d "Solitas-NormBook.otf"
EXIT
Please sign in to leave a comment.
Comments
24 comments