Th3_uN1Qu3 Posted June 24, 2008 Posted June 24, 2008 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. I guess this is one of the moments i'd be much happier running Linux.
ricktendo Posted June 24, 2008 Posted June 24, 2008 (edited) If you copy it then do reg add you could probably achieve thisExample:reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "FontName (TrueType)" /t REG_SZ /d FontName.ttf /f Edited June 24, 2008 by ricktendo64 1
Th3_uN1Qu3 Posted June 24, 2008 Author Posted June 24, 2008 (edited) If you copy it then do reg add you could probably achieve thisExample:reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "FontName (TrueType)" /t REG_SZ /d FontName.ttf /fI 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 June 24, 2008 by Th3_uN1Qu3
Tripredacus Posted June 24, 2008 Posted June 24, 2008 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() FunctionWMSysColorChange() FunctionWM_THEMECHANGEDPostMessage() FunctionSendMessage() HWND_BROADCASTSendMessageA ( 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.
gunsmokingman Posted June 24, 2008 Posted June 24, 2008 Try this script make sure the font is in the same folder as this script.Save as AddFont.vbsConst 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 1
Th3_uN1Qu3 Posted June 24, 2008 Author Posted June 24, 2008 (edited) 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 June 24, 2008 by Th3_uN1Qu3
Th3_uN1Qu3 Posted June 24, 2008 Author Posted June 24, 2008 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.
Th3_uN1Qu3 Posted June 24, 2008 Author Posted June 24, 2008 How about reading the whole post? I got it done. 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.
cluberti Posted June 24, 2008 Posted June 24, 2008 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.
gunsmokingman Posted June 24, 2008 Posted June 24, 2008 Read this article from the Hey, Scripting Guy! and you will see it the correct way.How Can I Install Fonts Using a Script?
Tripredacus Posted June 26, 2008 Posted June 26, 2008 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.
Th3_uN1Qu3 Posted June 27, 2008 Author Posted June 27, 2008 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.
Th3_uN1Qu3 Posted August 17, 2008 Author Posted August 17, 2008 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...
HippoMan Posted November 19, 2009 Posted November 19, 2009 (edited) 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 November 19, 2009 by HippoMan
ckislam Posted January 16, 2012 Posted January 16, 2012 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 oradd the source folder as a parameter. for example "ADD_fonts.cmd" C:\Folder 1\Folder 2\@ECHO OFFTITLE Adding Fonts..REM Filename: ADD_Fonts.cmdREM Script to ADD TrueType and OpenType Fonts for WindowsREM By Islam AdelREM 2012-01-16REM 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 allowedREM 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 %%iREM OPTIONAL REBOOTREM shutdown -r -f -t 10 -c "Reboot required for Fonts installation"ECHO.ECHO Done!PAUSEEXIT:FONTECHO.REM ECHO FILE=%~f1SET FFILE=%~n1%~x1SET FNAME=%~n1SET 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%" /fGOTO :EOFADD_Fonts.cmd 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now