Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

How to install a font via the command line?

- - - - -

  • Please log in to reply
15 replies to this topic

#1
Th3_uN1Qu3

Th3_uN1Qu3

    Digital sinner

  • Member
  • PipPipPip
  • 386 posts
  • Joined 17-March 08
Yes, i've searched. But none of the solutions worked.

I have an application that requires a font installed. A single font, with only one version, and i need that font installed via the command line, without having to reboot the system. I have tried restarting the explorer.exe process, when i do that the font does appear in Explorer but is still unavailable in my application. Any clues on how to fix this? Fontinst.exe does not work either, as it is an OTF font.

I find it stupid that you can install a font without rebooting by simply dropping it into the fonts folder, but you can't mimic this behaviour with a batch file. :blink: I guess this is one of the moments i'd be much happier running Linux.
What's the point of security features if we have to disable them for things to work right?

p35-ds3 / e6550 @ 3.5ghz 500fsb scythe mugen / 8gb pqi ddr2 800 @ 1000 / sapphire hd3870 / 320gb wd / x64 / nokia 920c 19"
toshi portege 4010 / p3 tualatin @ 933mhz / 512mb pc133 sdram / 16mb cyberblade / wifi / irda / sd / 30gb ibm / me / 12.1" tft
6bxds / 2x p3 @ 700mhz / 1gb cl2 sdram / sapphire 9800 pro 256mb / awe64 isa / sil3112a pci + 320gb wd / xp / thomson 24" tv


How to remove advertisement from MSFN

#2
ricktendo

ricktendo

    Group: Banned Members

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,307 posts
  • Joined 06-June 06
  • OS:Windows 7 x64
  • Country: Country Flag
If you copy it then do reg add you could probably achieve this

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

Edited by ricktendo64, 24 June 2008 - 12:21 AM.


#3
Th3_uN1Qu3

Th3_uN1Qu3

    Digital sinner

  • Member
  • PipPipPip
  • 386 posts
  • Joined 17-March 08

If you copy it then do reg add you could probably achieve this

Example:

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


I already did that, not like that but by importing a reg file. It doesn't work, the font doesn't even show up in the Fonts folder (although it is there) if i do that. I need to reboot to get it recognized...

Edited by Th3_uN1Qu3, 24 June 2008 - 06:43 AM.

What's the point of security features if we have to disable them for things to work right?

p35-ds3 / e6550 @ 3.5ghz 500fsb scythe mugen / 8gb pqi ddr2 800 @ 1000 / sapphire hd3870 / 320gb wd / x64 / nokia 920c 19"
toshi portege 4010 / p3 tualatin @ 933mhz / 512mb pc133 sdram / 16mb cyberblade / wifi / irda / sd / 30gb ibm / me / 12.1" tft
6bxds / 2x p3 @ 700mhz / 1gb cl2 sdram / sapphire 9800 pro 256mb / awe64 isa / sil3112a pci + 320gb wd / xp / thomson 24" tv

#4
Tripredacus

Tripredacus

    K-Mart-ian Legend

  • Super Moderator
  • 9,814 posts
  • Joined 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Donator

I looked into this option when trying to write a program that installs a custom desktop settings and screensaver. The screensaver was 3d text, and I installed a font from a network share. Yes indeed the problem is that you ultimately need to reload explorer so it recognizes the new font. Otherwise it just show up as your system default (ie Arial) font until you reboot. I struggled with this process for a long time before I just made my program reboot at the end.

I looked into making Explorer refresh itself, which is the process that happens after you load a new color scheme, or switch from XP to classic. When that "please wait" box shows up and your desktop turns grayscale, also this happens when you logoff. Here are the things I wrote down in my notes. I don't know exactly what they mean now. I think I was trying to call the system command that triggered the "Theme Change" so it would re-read the font.

SetSysColors() Function
WMSysColorChange() Function
WM_THEMECHANGED
PostMessage() Function
SendMessage() HWND_BROADCAST

SendMessageA ( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 )
RedrawWindow ( GetDesktopWindow(), NULL, 0, RDW_Invalidate | RDW_Erase | RDW_UPDATENOW | RDW_ALLCHILDREN );


Anyways I was doing this through AUTOit but like I said I couldn't figure it out. So unless you can get Windows to recognize a theme change and redraw the desktop, you'll need to reboot. Not even restarting explorer.exe (the existing process) allowed the change to occur.

Or perhaps there is another way to automate the installation of a font.
MSFN RULES | GimageX HTA for PE 3-5 | lol probloms
msfn2_zpsc37c7153.jpg

#5
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
Try this script make sure the font is in the same folder as this script.
Save as AddFont.vbs

Const FONTS = &H14&
'/-> Path And Name To Font
 Dim Font :Font =  "PATH_FONT_NAME_HERE"
'/-> Objects				  
 Dim Folder, Fso, Shell
 Set Fso = CreateObject("Scripting.FileSystemObject")
 Set Shell = CreateObject("Shell.Application")
 Set Folder = Shell.Namespace(FONTS)
'/-> Check For File Exists
 If Fso.FileExists(Font) Then 
  Folder.CopyHere Font
 Else
  MsgBox "Missing " & Font,4128,"Missing Font"
 End If




GunSmokingMan



#6
Th3_uN1Qu3

Th3_uN1Qu3

    Digital sinner

  • Member
  • PipPipPip
  • 386 posts
  • Joined 17-March 08
That script did nothing... It didn't even copy the file to the fonts dir.

Edit: This has got to be THE STUPIDEST THING EVER. I just did it with FileCopy in AutoIt and it installs no problem, and my application uses it. No flashing windows, nothing, nice and clean. This proves that XCOPY is different from the actual GUI copy command...

Edited by Th3_uN1Qu3, 24 June 2008 - 12:33 PM.

What's the point of security features if we have to disable them for things to work right?

p35-ds3 / e6550 @ 3.5ghz 500fsb scythe mugen / 8gb pqi ddr2 800 @ 1000 / sapphire hd3870 / 320gb wd / x64 / nokia 920c 19"
toshi portege 4010 / p3 tualatin @ 933mhz / 512mb pc133 sdram / 16mb cyberblade / wifi / irda / sd / 30gb ibm / me / 12.1" tft
6bxds / 2x p3 @ 700mhz / 1gb cl2 sdram / sapphire 9800 pro 256mb / awe64 isa / sil3112a pci + 320gb wd / xp / thomson 24" tv

#7
Th3_uN1Qu3

Th3_uN1Qu3

    Digital sinner

  • Member
  • PipPipPip
  • 386 posts
  • Joined 17-March 08
As i said, i only need ONE font, and it's in OTF. Fontinst does not work. But see above, AutoIt worked... Windoze is strange.
What's the point of security features if we have to disable them for things to work right?

p35-ds3 / e6550 @ 3.5ghz 500fsb scythe mugen / 8gb pqi ddr2 800 @ 1000 / sapphire hd3870 / 320gb wd / x64 / nokia 920c 19"
toshi portege 4010 / p3 tualatin @ 933mhz / 512mb pc133 sdram / 16mb cyberblade / wifi / irda / sd / 30gb ibm / me / 12.1" tft
6bxds / 2x p3 @ 700mhz / 1gb cl2 sdram / sapphire 9800 pro 256mb / awe64 isa / sil3112a pci + 320gb wd / xp / thomson 24" tv

#8
Th3_uN1Qu3

Th3_uN1Qu3

    Digital sinner

  • Member
  • PipPipPip
  • 386 posts
  • Joined 17-March 08
How about reading the whole post? I got it done. :P Anyway, the app i am working on is also stupidly weird. If i run it via the shortcut after installing the font, the font doesn't work. If i run it via the autoplay, it works...

We can consider this solved though. The autoplay and the setup program are the same exe, therefore the autoplay must be run to install the app, so the font will work too.
What's the point of security features if we have to disable them for things to work right?

p35-ds3 / e6550 @ 3.5ghz 500fsb scythe mugen / 8gb pqi ddr2 800 @ 1000 / sapphire hd3870 / 320gb wd / x64 / nokia 920c 19"
toshi portege 4010 / p3 tualatin @ 933mhz / 512mb pc133 sdram / 16mb cyberblade / wifi / irda / sd / 30gb ibm / me / 12.1" tft
6bxds / 2x p3 @ 700mhz / 1gb cl2 sdram / sapphire 9800 pro 256mb / awe64 isa / sil3112a pci + 320gb wd / xp / thomson 24" tv

#9
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,252 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag
The reason AutoIT worked is because copying the file over via the shell into the fonts folder automatically tells explorer to call the APIs to install the font (AddFontResourceEx and CreateScalableFontResource to install the font, and SendMessage with the WM_FONTCHANGE message to all top-level windows on the system), whereas using a manual copy outside of the shell doesn't invoke the APIs and thus a reboot / reload of explorer is required.

If you aren't the code writing sort, and you need it to work without a reboot, AutoIT is really your only option.
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!

#10
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
Read this article from the Hey, Scripting Guy! and you will see it the correct way.

How Can I Install Fonts Using a Script?



GunSmokingMan



#11
Tripredacus

Tripredacus

    K-Mart-ian Legend

  • Super Moderator
  • 9,814 posts
  • Joined 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Donator

That is interesting because my autoit app can install the font but it won't work with the 3d text screensaver until the computer is rebooted.
MSFN RULES | GimageX HTA for PE 3-5 | lol probloms
msfn2_zpsc37c7153.jpg

#12
Th3_uN1Qu3

Th3_uN1Qu3

    Digital sinner

  • Member
  • PipPipPip
  • 386 posts
  • Joined 17-March 08

The reason AutoIT worked is because copying the file over via the shell into the fonts folder automatically tells explorer to call the APIs to install the font (AddFontResourceEx and CreateScalableFontResource to install the font, and SendMessage with the WM_FONTCHANGE message to all top-level windows on the system), whereas using a manual copy outside of the shell doesn't invoke the APIs and thus a reboot / reload of explorer is required.

If you aren't the code writing sort, and you need it to work without a reboot, AutoIT is really your only option.


Thanks for clearing that up. I am a bit of a coder but if i can get it done easier then why not. :)
What's the point of security features if we have to disable them for things to work right?

p35-ds3 / e6550 @ 3.5ghz 500fsb scythe mugen / 8gb pqi ddr2 800 @ 1000 / sapphire hd3870 / 320gb wd / x64 / nokia 920c 19"
toshi portege 4010 / p3 tualatin @ 933mhz / 512mb pc133 sdram / 16mb cyberblade / wifi / irda / sd / 30gb ibm / me / 12.1" tft
6bxds / 2x p3 @ 700mhz / 1gb cl2 sdram / sapphire 9800 pro 256mb / awe64 isa / sil3112a pci + 320gb wd / xp / thomson 24" tv

#13
Th3_uN1Qu3

Th3_uN1Qu3

    Digital sinner

  • Member
  • PipPipPip
  • 386 posts
  • Joined 17-March 08
I thought this was over with but it seems it's not.

I tested it 3 times on fresh installs of XP and Vista under Virtual PC. Everything worked fine. I left that project alone for some time since i had other stuff to do and things were getting more complicated, and now i've returned to it.

Tried it on my dual-PIII running XP. The font is copied, if i try to copy it manually it says it's already installed, BUT IT DIDN'T WORK EVEN AFTER A REBOOT. If i delete the font manually then copy it again, or use the installer, or whatever, it works.

W-T-F. Since it works now i can't recreate the issue either...
What's the point of security features if we have to disable them for things to work right?

p35-ds3 / e6550 @ 3.5ghz 500fsb scythe mugen / 8gb pqi ddr2 800 @ 1000 / sapphire hd3870 / 320gb wd / x64 / nokia 920c 19"
toshi portege 4010 / p3 tualatin @ 933mhz / 512mb pc133 sdram / 16mb cyberblade / wifi / irda / sd / 30gb ibm / me / 12.1" tft
6bxds / 2x p3 @ 700mhz / 1gb cl2 sdram / sapphire 9800 pro 256mb / awe64 isa / sil3112a pci + 320gb wd / xp / thomson 24" tv

#14
HippoMan

HippoMan
  • Member
  • 1 posts
  • Joined 19-November 09
I know this is an old thread, but I have a new twist to this issue.

I do not have write access to %SystemRoot%\Fonts on my WinXP system, nor do I have the rights to alter HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts. I can still install a font using the Fonts Control Panel applet, however, and this installation is valid only for the current login session.

What I'm looking for is a way via the command line to install a font for the current login session, and I don't want to have to make use of any manual interaction via a GUI. This way, I can wrap this in a program or script that automatically runs on login.

In other words, I'm looking for a command-line-specific way to install a font in the same way that the Fonts applet will do it if Copy fonts to Fonts folder is unchecked.

I'm willing to write a program in C, C++, C#, VB, or any other language, if that's is the only way to accomplish this.

Any ideas as to how I can do this?

Thanks in advance.

Edited by HippoMan, 19 November 2009 - 08:38 AM.


#15
ckislam

ckislam

    Islam Adel

  • Member
  • PipPip
  • 142 posts
  • Joined 04-September 05
  • OS:Windows 7 x64
  • Country: Country Flag
Here is a batch script to install Fonts in any Folder automatically.
Paste the following code in notepad and save it as "ADD_Fonts.cmd"
place the cmd file inside the folder of the fonts you want to install and run it or
add the source folder as a parameter. for example "ADD_fonts.cmd" C:\Folder 1\Folder 2\

@ECHO OFF
TITLE Adding Fonts..
REM Filename: ADD_Fonts.cmd
REM Script to ADD TrueType and OpenType Fonts for Windows
REM By Islam Adel
REM 2012-01-16

REM 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=%*
ECHO.
ECHO Adding Fonts..
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"
ECHO.
ECHO Done!
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

Attached Files


Islam Adel
TGUP Posted ImagePosted Image

#16
kali

kali

    KamrulCox

  • Member
  • Pip
  • 76 posts
  • Joined 17-April 11
  • OS:none specified
  • Country: Country Flag
I am writing what I do for this tips.
First keep your all fonts in a folder where ever you like. Then make a command file (like Install fonts.bat) with following script.

copy *.ttf "%windir%\Fonts"

here you can add another command for another file extensions. Save the file (install fonts.bat) in same folder. It will copy all your desire fonts into fonts folder of your PC.

Now make a reg file (like fonts.reg) with following commands to entry the fonts into registry.

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"Times New Roman (TrueType)"="TIMES.TTF"


Now run the reg file with following command
regedit /s Registryfile.reg

You can make a command file with tow command file describe above like following.
copy *.ttf "%windir%\Fonts"
regedit /s fonts.reg


I added a fonts in reg file. You can also a fonts from your list. It will index all fonts after restarts. Keep all the files in same folder with fonts. After all Restart your PC.

Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN