-
-
Save nathanverrilli/d3f12fbad87953e28aae78b5f191cdab to your computer and use it in GitHub Desktop.
param ( | |
[string]$FontName, | |
[string]$FontFile, | |
[switch]$Help | |
); | |
function isAdminMode() { | |
return ([Security.Principal.WindowsPrincipal] ` | |
[Security.Principal.WindowsIdentity]::GetCurrent() ` | |
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
} | |
#################################### | |
# NULL comes in a number of shapes and forms in powershell | |
function isNull($obj) { | |
if ( ($obj -eq $null) -or | |
(($obj -is [String]) -and ($obj -eq [String]::Empty)) -or | |
($obj -is [DBNull]) -or | |
($obj -is [System.Management.Automation.Language.NullString]) ) | |
{ return $true; } | |
return $false; | |
} | |
#################################### | |
function printHelp { | |
write-host " " | |
write-host " Usage: $scriptName -FontName <fontname> -FontFile <truetypefontfile>" | |
write-host " add font <fontname> in <truetypefontfile> to console fonts registry key" | |
write-host " <truetypefontfile> must be present in system fonts directory" | |
write-host " Please note that only truetype (.ttf) fonts may be installed to the powershell terminal" | |
write-host " Please note that this script must be run with elevated permissions" | |
write-host " " | |
write-host " Usage: $scriptName -Help" | |
write-host " print this message" | |
write-host " " | |
write-host " Example: ./$scriptName 'Zen Mono Regular' -FontFile zenmono-r-6.1.3.ttg" | |
write-host " " | |
exit 0; | |
} | |
#################################### | |
#the script name might be 'InstallConsoleFont' but it might have been changed, too | |
$scriptName = $MyInvocation.MyCommand.Name | |
$adminMode = isAdminMode | |
if ( ($Help) -or | |
(isNull($FontName)) -or | |
(isNull($FontFile)) -or | |
(-not $adminMode ) ) { | |
printHelp | |
} | |
$key = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont" | |
## Find out if $FontName is installed on the system | |
$fontFileName = join-path $env:windir "Fonts\$FontFile" | |
if(!(test-path $fontFileName)) | |
{ | |
write-host "File $fontFileName is not present." | |
write-host "Please check that the desired font is installed in a .TTF format" | |
printHelp | |
break | |
} | |
## Determine if $FontName is already installed as a command window font | |
$installed = get-itemproperty $key | | |
get-member | | |
where-object { $_.Name -match "^0+$" } | | |
where-object { $_.Definition -match "$FontName" } | |
if($installed -ne $null) | |
{ | |
write-host "The $FontName font is already installed as a command window font" | |
write-host "or another font is installed with that name ( $FontName )" | |
write-host " " | |
break | |
} | |
## Find out what the largest string of zeros is | |
$zeros = (get-itemproperty $key | | |
get-member | | |
where-object { $_.Name -match "^0+$" } | | |
measure-object).Count | |
## Install the font | |
new-itemproperty $key -Name ("0" * ($zeros + 1)) -Type string -Value "$FontName" | |
write-host "$FontName font installed successfully as a command window font." | |
Hi Taylor!
A .FON
file is not a true type font, but (if I recall correctly) an executable file with (potentially) multiple old-style .FNT
fonts. Supposedly this does support some vectorized glyphs, but I've only ever seen bitmapped fonts (I think. It's been a long time since I played with these).
This installation script only works for modern truetype fonts.
I suspect it did get installed as a registry key (HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
) but PowerShell can't use it because it's listed as a TrueTypeFont
rather than under RasterFonts
DANGER use Regedit
You will need to use Regedit to fix/install the font. Please remember that you must run Regedit in administrator mode to make changes (rather than view) the registry. I am certain you are aware of the infinite amount of damage and destruction misuse of regedit can cause to a windows installation, but I feel strongly about putting DANGER markers anytime something is that dangerous. One never knows who is going to read this or in what context.
Rollback:
- Remove the invalid key (with the .FON file) at
HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
Possible Fix
Please note that there might be some key naming convention (like the string of 0
characters for truetype fonts) that I am unaware of.
as in, it MIGHT work but I do not know enough to say for certain:
- Try installing the key at
HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\RasterFonts
. Be certain that Windows has already installed the font.
Suggested Course of Action
If I were trying to do this, I would experiment in an VM first, but then I am a cautious soul who would rather spend 3 minutes spinning up a VM to test with than 3 days rebuilding my production machine.
Please let me know if this is helpful!
Cheers,
N
Hi Taylor!
A
.FON
file is not a true type font, but (if I recall correctly) an executable file with (potentially) multiple old-style.FNT
fonts. Supposedly this does support some vectorized glyphs, but I've only ever seen bitmapped fonts (I think. It's been a long time since I played with these).This installation script only works for modern truetype fonts.
I suspect it did get installed as a registry key (
HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
) but PowerShell can't use it because it's listed as aTrueTypeFont
rather than underRasterFonts
DANGER use Regedit
You will need to use Regedit to fix/install the font. Please remember that you must run Regedit in administrator mode to make changes (rather than view) the registry. I am certain you are aware of the infinite amount of damage and destruction misuse of regedit can cause to a windows installation, but I feel strongly about putting DANGER markers anytime something is that dangerous. One never knows who is going to read this or in what context.
Rollback:
* Remove the invalid key (with the .FON file) at `HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont`
Possible Fix
Please note that there might be some key naming convention (like the string of
0
characters for truetype fonts) that I am unaware of.as in, it MIGHT work but I do not know enough to say for certain:
* Try installing the key at `HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\RasterFonts`. Be certain that Windows has already installed the font.
Suggested Course of Action
If I were trying to do this, I would experiment in an VM first, but then I am a cautious soul who would rather spend 3 minutes spinning up a VM to test with than 3 days rebuilding my production machine.
Please let me know if this is helpful!
Cheers, N
Followed what you said an unfortunately I still don't see it under fonts when I right click on powershell after running as administrator and going to fonts under properties. I also changed the way it's named to follow the other stuff in the registry and it still didn't work. It's fine though, if it's not going to work i'm not super worried about it. Just thought I'd give it a try.
Oh and yeah, windows does have it installed because I can see it under C:\Windows\Fonts
So I installed a font called "Terminal" which has it's file named vgaoem.fon - so I used the command like this, "./ConsolFont.ps1 'Terminal' -FontFile vgaoem.fon" I then got this message, "Terminal font installed successfully as a command window font." so I assumed that it worked however not only do I not see it anywhere, I even tried to manually select it via the properties in WindowsPowershell and Command Prompt through the fonts tab and don't see it. Am I doing something wrong?
Here is the full log,
"000 : Terminal
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Console\TrueTypeFont
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Console
PSChildName : TrueTypeFont
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
Terminal font installed successfully as a command window font."