Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 489 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows: install fonts from cmd/.bat file

#1
anyone know how to install font files (.ttf, .TTF, .otf, .OTF, etc etc) through the command prompt on windows?

as i understand it, it requires moving the text file to the correct folder and then also creating a registry value i think? but I havent been able to find one that is confirmed working.

a note: I am using windows 8 so that might make a difference.

another note: what I am trying to do is batch install fonts that I ripped from MKV files. (so this will be a function that is part of a larger .bat file, i can post the code if needed)
Reply

#2
Have you tried copying them to the font's folder?

copy font.ttf %windir%\Fonts
Reply

#3
maybe this is needed too:

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

#4
When you install a font all it does is copy the .ttf file to `%systemroot%\fonts` and add an entry in `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts`. This can be automated with a batch file as follows


Rem fontinst.bat

copy akbar.ttf %systemroot%\fonts

regedit /s font.reg

The font.reg would contain the following:


REGEDIT4

\[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\]

"Akbar Plain (TrueType)"="akbar.ttf"

Source: m.windowsitpro.com





Reply

#5
You'll need to use a PowerShell or VB script. They basically re-use the shell components that do the same thing in Windows Explorer, and they don't need a reboot.

See here for a PowerShell script that installs all fonts from a directory for Windows 8.1 or earlier:

[To see links please register here]


Here is a similar script for Windows 10 (Windows Server 2019) that also updates the Windows Registry:

[To see links please register here]


Also, you'll need to run the script in admin mode. So if the PowerShell script is InstallFonts.ps1, your batch file needs to look like:

powershell -command "Set-ExecutionPolicy Unrestricted" 2>> err.out
powershell .\InstallFonts.ps1 2>> err.out

Any powershell errors will appear in 'err.out' on the same folder as the script.
Reply

#6
Batch file sample. It works in the current directory.


IF "%*" NEQ "" SET FONT=%* (

FOR /F %%i in ('dir /b "%FONT%*.*tf"') DO CALL :DEST %%i

) else (

EXIT

)

:DEST

SET FONTFILE=%~n1%~x1
SET FONTNAME=%~n1


IF "%~x1"==".ttf" SET FONTTYPE=TrueType
IF "%~x1"==".otf" SET FONTTYPE=OpenType

ECHO FILE = %FONTFILE%
ECHO NAME = %FONTNAME:-= %
ECHO TYPE = %FONTTYPE%

fontview %~dp0%FONTFILE%


GOTO :EXIT


Reply

#7
I solved the task in this way:

suppose you have to install many fonts in subfolders with the following structure recursively:

\root_folder
Install_fonts.cmd
\font_folder_1
font_1.ttf
font_2.otf
\font_folder_2
font_3.ttf
font_4.otf
\font_folder_3
font_5.ttf
font_6.otf

To do that, I downloaded the *[FontReg.exe][1]* tool on my **Desktop** (change the `path` in the `Install_fonts.cmd` file if it is located somewhere else) and I used it in a `Install_fonts.cmd` batch script like the following, located in `root_folder` (change also its name in the `Install_fonts.cmd` file, if different):

@echo off
set back=%cd%
for /d %%i in (%USERPROFILE%\Desktop\root_folder\*) do (
cd "%%i"
echo current directory:
cd
start /wait %USERPROFILE%\Desktop\fontreg-2.1.3-redist\bin.x86-64\FontReg.exe /move
timeout /t 1 /nobreak >nul
)
cd %back%
echo Process completed!
pause

So, you have to run `Install_fonts.cmd` into `root_folder` as **administrator**, to automate the fonts installation process.

Cheers

[1]:

[To see links please register here]

Reply

#8
So a colleague and I found a powershell solution that requires no admin rights, and does not show any prompts. You can use the name of the font-file to install *and* uninstall. This makes it especially useful for scripting.

Install:
```ps
# Install-Font.ps1
param($file)

$signature = @'
[DllImport("gdi32.dll")]
public static extern int AddFontResource(string lpszFilename);
'@

$type = Add-Type -MemberDefinition $signature `
-Name FontUtils -Namespace AddFontResource `
-Using System.Text -PassThru

$type::AddFontResource($file)
```

Uninstall:
```ps
# Uninstall-Font.ps1
param($file)

$signature = @'
[DllImport("gdi32.dll")]
public static extern bool RemoveFontResource(string lpszFilename);
'@

$type = Add-Type -MemberDefinition $signature `
-Name FontUtils -Namespace RemoveFontResource `
-Using System.Text -PassThru

$type::RemoveFontResource($file)
```

You can use them like this from cmd or powershell:
```cmd
> powershell -executionpolicy bypass -File .\Install-Font.ps1 .\myfonts\playfair-display-v22-latin-regular.ttf
> powershell -executionpolicy bypass -File .\Uninstall-Font.ps1 .\myfonts\playfair-display-v22-latin-regular.ttf
```

The solution is based on

[To see links please register here]

and uses native Win32 functions (`gdi32.dll`).

[To see links please register here]

Reply

#9
if you are a python fan, following script does the job. This script generates a vbscript for font installation. Searches all the sub-folders for ttf fonts and installs it. You don't need to move any font files.

```python
import os
import subprocess
import time

# vb script template
_TEMPL = """
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("%s")
Set objFolderItem = objFolder.ParseName("%s")
objFolderItem.InvokeVerb("Install")
"""


vbspath = os.path.join(os.getcwd(), 'fontinst.vbs')

for directory, dirnames, filenames in os.walk(os.getcwd()):
for filename in filenames:
fpath = os.path.join(directory, filename)

if fpath[-4:] == ".ttf": # modify this line for including multiple extension
with open(vbspath, 'w') as _f:
_f.write(_TEMPL%(directory, filename))
subprocess.call(['cscript.exe', vbspath])
time.sleep(3) # can omit this

os.remove(vbspath) # clean
```
Run this python script on the root folder
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through