Jump to content

Auto Install Fonts from folder


Recommended Posts

On post #9 of this thread -

there's a script which I was hoping would work but it doesnt. I assume some syntax has changed since then. I've googled and searched the forums but everything I come across doesnt work. Very new to AutoIT and writing scripts so was hoping someone already had a font install script that I could add to my existing one?

Link to comment
Share on other sites

  • Moderators

@Silverback83 "doesn't work" doesn't help anyone. The function you linked to seems to have decent error checking, so how about explaining in detail what it is or isn't doing? Are you getting an error in the SciTE output pane? Help us help you ;)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@JLogan3o13 I'm getting Exit code 0 but I think exit code 0 means it executed ok yet it doesnt actually do anything when I run the script.

I'm not trying to be vague. It just doesnt do anything when I run the script. If it is, I certainly cant see anything happening. It doesnt install the fonts. I'm not trying to be a pain. I just dont know what other info to post :P

Link to comment
Share on other sites

  • Moderators

@Silverback83  no one is saying you're being a pain, just trying to gather more information. Something as simple as what you wrote above is helpful as forum members try to assist you. Sometimes we get into a rut of posting "it's broke!" without realizing that it doesn't fully explain what we are (or are not!) seeing.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Have you checked after a reboot, to see if the fonts are installed?  Here is a similar function that I use to install fonts, but it requires a system reboot for them to show up.  

#include <WinAPIGdi.au3>
#include <WinAPIShellEx.au3>

Func _FontInstall($sFile)

    Local $Font, $Name, $Path

    $Name = _WinAPI_GetFontResourceInfo($sFile, True)
    If @error Then
        Return SetError(1, 0, 0)
    EndIf
    $Name &= ' (TrueType)'
    $Font = StringRegExpReplace($sFile, '^.*\\', '')
    If Not RegWrite('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', $Name, 'REG_SZ', $Font) Then
        Return SetError(2, 0, 0)
    EndIf
    $Path = _WinAPI_ShellGetSpecialFolderPath($CSIDL_FONTS)
    If Not FileCopy($sFile, $Path) Then
        RegDelete('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', $Name)
        Return SetError(3, 0, 0)
    EndIf
    If Not _WinAPI_AddFontResourceEx($Path & '\' & $Font, 0, True) Then
        Return SetError(4, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_FontInstall

 

Adam  

Link to comment
Share on other sites

Here is the .bat File I use.

I love Autoit but when I can do it with native .BAT files I usually go that route.

 

@ECHO OFF
TITLE Adding Fonts..
REM Filename: ADD_Fonts.cmd
REM Script to ADD TrueType and OpenType Fonts for Windows


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

 

Link to comment
Share on other sites

13 hours ago, ViciousXUSMC said:

Here is the .bat File I use.

I love Autoit but when I can do it with native .BAT files I usually go that route.

 

@ECHO OFF
TITLE Adding Fonts..
REM Filename: ADD_Fonts.cmd
REM Script to ADD TrueType and OpenType Fonts for Windows


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

 

Hey, thanks for this. I tried this but all I get is 'Error: Access is denied." on each font I see whizzing through CMD. Didnt even occur to me to try and do this with a batch file and then just run the file as part of my script. Least I'm on the right path now *goes to google solution*

Edit: Ok, so I think its because its not running as admin, even though  am. If I run as admin it does nothing. I found a compiler that turns vbs into exe's (So I could still do this and then run as part of my autoit script) but I cant work out how to put in the path of fonts (as if turning into an exe, it doesnt matter if its located within the same folder as the fonts.

I tried to edit the C:\folder bit above but guessing I need to do something else as still not working. Feels rather close though.

Edited by Silverback83
Link to comment
Share on other sites

12 hours ago, AdamUL said:

Have you checked after a reboot, to see if the fonts are installed?  Here is a similar function that I use to install fonts, but it requires a system reboot for them to show up.  

#include <WinAPIGdi.au3>
#include <WinAPIShellEx.au3>

Func _FontInstall($sFile)

    Local $Font, $Name, $Path

    $Name = _WinAPI_GetFontResourceInfo($sFile, True)
    If @error Then
        Return SetError(1, 0, 0)
    EndIf
    $Name &= ' (TrueType)'
    $Font = StringRegExpReplace($sFile, '^.*\\', '')
    If Not RegWrite('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', $Name, 'REG_SZ', $Font) Then
        Return SetError(2, 0, 0)
    EndIf
    $Path = _WinAPI_ShellGetSpecialFolderPath($CSIDL_FONTS)
    If Not FileCopy($sFile, $Path) Then
        RegDelete('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', $Name)
        Return SetError(3, 0, 0)
    EndIf
    If Not _WinAPI_AddFontResourceEx($Path & '\' & $Font, 0, True) Then
        Return SetError(4, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_FontInstall

 

Adam  

Hey Adam. Thanks for the reply. Cant really see in your scipt what I need to edit to get it to install a folder of fonts? Also, Is there a way of doing this without a reboot?

Link to comment
Share on other sites

Look at _FileListToArray to get an array of font files, and then loop through the array using the _FontInstall function.  I haven't found a way to do it via script without a reboot.  There may be a way to do it, but i don't know how.  

 

Adam

 

Link to comment
Share on other sites

15 hours ago, Silverback83 said:

Hey, thanks for this. I tried this but all I get is 'Error: Access is denied." on each font I see whizzing through CMD

Looks like you lack the rights to install fonts - which requires writing to the registry and creating files in a system directory so it doesn't surprise me.

You will need to run this at an elevated level.

.... Or you could just register the fonts for your current session using GDI+. The font's will work like they are installed until you log off. -- Look at _WinAPI_AddFontResourceEx()

Link to comment
Share on other sites

On 31/03/2017 at 10:29 PM, IErrors said:

Looks like you lack the rights to install fonts - which requires writing to the registry and creating files in a system directory so it doesn't surprise me.

You will need to run this at an elevated level.

.... Or you could just register the fonts for your current session using GDI+. The font's will work like they are installed until you log off. -- Look at _WinAPI_AddFontResourceEx()

I'm already admin. If I tell it to run as admin it does nothing. I need them installed on a perm basis. I think I may have found a way, will report back after I can test it.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...