How do I install a font from the Windows command prompt?

38

12

Is it possible to install fonts from the command prompt on Windows? If yes, what is the command?

I tried copy [fontname].ttf C:\Windows\Fonts\ and it said copying was complete, but I could neither find the said fonts in the Fonts folder nor find them in the font list of any program so that certainly didn't work. (Although I was able to delete the said fonts from the Fonts folder afterwards)

Mussnoon

Posted 2010-10-21T12:58:51.567

Reputation: 918

Answers

31

It's possible but you have to write a Windows shell script to do that. Copying alone won't install the font: you also need to register the font, e.g.

copy "FontName.ttf" "%WINDIR%\Fonts"
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "FontName (TrueType)" /t REG_SZ /d FontName.ttf /f

Alternatively you can the following lines of code to suit your needs; save it as a .vbs file and then execute it.

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("<Folder or Share Location>")
Set objFolderItem = objFolder.ParseName("<TTF File Name>")
objFolderItem.InvokeVerb("Install")

Example:

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Windows\Font")
Set objFolderItem = objFolder.ParseName("Myriad Pro.ttf")
objFolderItem.InvokeVerb("Install")

Yet another alternative is to install fonts "temporary", just for current user session. The idea is to run fontview.exe for each font, which makes it available for other Windows applications:

for /F "delims=;" %%a in ('dir C:\ExtraFonts /B /A-D-H-S /S') do fontview %%a

See the complete solution here.

GeneQ

Posted 2010-10-21T12:58:51.567

Reputation: 4 581

1objFolderItem.InvokeVerb("Install") does not work on Windows Server 2012 R2 – Anthony Kong – 2014-11-10T22:57:40.587

@GeneQ : Thecopyandreg adddoesn’t makes the font listed in programs in Windows® 10. – user2284570 – 2016-07-07T13:34:59.580

Will you be so kind to extend your script to: (1) Automatically install all *.ttf and *.fon fonts from current directory (2) Use Const FONTS = &H14& as suggested here (http://www.sevenforums.com/general-discussion/28817-installing-fonts-via-command-line-script.html#post503533). I am not king on VBS :( Thanks in advance.

– dma_k – 2011-08-17T13:09:37.817

16

In Powershell this can be as simple as:

$fonts = (New-Object -ComObject Shell.Application).Namespace(0x14)
dir fonts/*.ttf | %{ $fonts.CopyHere($_.fullname) }

Guss

Posted 2010-10-21T12:58:51.567

Reputation: 583

3I would change second line with Get-ChildItem -Recurse -include *.ttf | % { $fonts.CopyHere($_.fullname) } – EvgeniySharapov – 2016-12-07T23:18:58.210

2Granted, Get-ChildItem is the Powershell way, I just hate the Powershell way (Unix shell affectionado here), and dir is just an alias for that; and if you want recursion, then the options you provided are the way to go. For the simple "just scan the files in this folder", my version is less verbose and more readable. – Guss – 2016-12-08T09:51:02.207

6

Similar to GeneQ's solution, here is a version doing it for all .ttf files in the script's directory:

Set ofso = CreateObject("Scripting.FileSystemObject")
SourceFolder = ofso.GetParentFolderName(Wscript.ScriptFullName)

Const FONTS = &H14&

Set objShell  = CreateObject("Shell.Application")
Set oSource   = objShell.Namespace(SourceFolder)
Set oWinFonts = objShell.Namespace(FONTS)

' Lame VBscript needs 4 f*ing lines instead of "if (/\.ttf$/i) " ...
Set rxTTF = New RegExp
rxTTF.IgnoreCase = True
rxTTF.Pattern = "\.ttf$"

FOR EACH FontFile IN oSource.Items()
    IF rxTTF.Test(FontFile.Path) THEN   
        oWinFonts.CopyHere FontFile.Path
    END IF
NEXT

mivk

Posted 2010-10-21T12:58:51.567

Reputation: 2 270

You just saved my day :) My default Windows font got corrupted and this was the only way I could reinstall all Windows Default fonts. Thanks!! – Rima – 2015-11-05T16:38:29.780

perfect! I used this in a vbs run by a bat file for a number of computers after a company re-brand. It installs the fonts, installs the email signature files for Outlook and sets the browser home page – Reece – 2015-11-19T00:47:09.420

3

You can also use the FontReg utility to install fonts from a command prompt.

afrazier

Posted 2010-10-21T12:58:51.567

Reputation: 21 316

1This didn't work for me on Windows 10 64bit. – djangofan – 2015-10-04T17:30:32.080

1@djangofan: Were you using an elevated command prompt? I haven't tried fontreg on Windows 10 yet, but I'd expect that to be required. – afrazier – 2015-10-04T18:23:09.337

The problem was I was trying to install Mac fonts on my system (they don't have filename extensions). I got the windows .ttf font files and its all good now. – djangofan – 2015-10-05T23:29:08.697

2

Create a script file called InstallFonts.vbs in my case I put it in C:\PortableApps\InstallFonts\ IN the below code replace "SomeUser" with the username of the person you want to be able to install fonts. Then make the Appropriate "install Fonts" folder on their desktop.

    Set ofso = CreateObject("Scripting.FileSystemObject")
'SourceFolder = ofso.GetParentFolderName(Wscript.ScriptFullName)
SourceFolder = "C:\Users\SomeUser\Desktop\Install Fonts"


Const FONTS = &H14&

Set objShell  = CreateObject("Shell.Application")
Set oSource   = objShell.Namespace(SourceFolder)
Set oWinFonts = objShell.Namespace(FONTS)

' Lame VBscript needs 4 f*ing lines instead of "if (/\.ttf$/i) " ...
Set rxTTF = New RegExp
rxTTF.IgnoreCase = True
rxTTF.Pattern = "\.ttf$"

FOR EACH FontFile IN oSource.Items()
    IF rxTTF.Test(FontFile.Path) THEN   
        oWinFonts.CopyHere FontFile.Path
    END IF
NEXT

Now create a shortcut on their desktop that is as follows...

C:\Windows\System32\runas.exe /user:Administrator /savecred "wscript C:\PortableApps\InstallFonts\InstallFonts.vbs"

Note that I used "Administrator". I enabled it and assigned it a password. I suppose you could use any administrator account for this. First time you run the shortcut you will be prompted for the administrator password.. every time after it will just work.

If it does not prompt you for a password run the shortcut from a cmd prompt it should prompt you then.

I cannot promise you how secure this is as in if they could use it to run elevated code. However it is a solution.

Desktop Masters

Posted 2010-10-21T12:58:51.567

Reputation: 21

0

As said earlier by GeneQ, this is how you proceed (I've tested it)

  1. Open a command line with administrator privileges
  2. Use the command:

for /F "delims=;" %a in ('dir C:\FontsDir /B /A-D-H-S /S') do fontview %a

Where C:\FontsDir is the directory where your tff files are stored. Once executed "fontview" windows will be opened as much as the number of tff files inside "FontsDir" directory. You have just to click on "Install" button and there you are! your fonts are installed on you system

Hope it would help someone

Sam Doxy

Posted 2010-10-21T12:58:51.567

Reputation: 101

why such a complex for command instead of (for example) for %a in (C:\FontsDir\*.*) do fontview "%a"? – Ale – 2016-01-19T00:17:32.223

The command shows also hidden fonts – Sam Doxy – 2016-04-06T12:17:14.663

-1

I spent a lot of time to find a way for installing font without restart. Finally I found this: ClickFont. It's an easy and exact solution.

ClickFont allows easy installation of TrueType, OpenType and PostScript fonts with just two mouse clicks, from anywhere in the system. All it takes is a right-click on a font or folder.

SelçukDERE

Posted 2010-10-21T12:58:51.567

Reputation: 1

-1

You didn't list your Windows version, but I assume you're running Vista or 7. Copying to that directory requires administrative privileges. Try what you did again, but use an Elevated Command Prompt instad this time.

jsejcksn

Posted 2010-10-21T12:58:51.567

Reputation: 2 854

4He said that the copy succeeded. If permissions were preventing him from successfully copying there, it would have told him that the copy failed, so this probably isn't the problem. – nhinkle – 2010-12-21T21:33:50.457