Sign in to follow this  
Followers 0
Silverback83

Auto Install Fonts from folder

12 posts in this topic

#1 ·  Posted

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted

@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 ;)

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

@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

Share this post


Link to post
Share on other sites

#4 ·  Posted

@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.

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#5 ·  Posted

So does anyone have any ideas? I'm happy to post more info, just not sure what.

I just need to work out how to install some fonts, and change the default association on .pdf's and I'm good to go (I think) :)

 

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

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  

Share this post


Link to post
Share on other sites

#7 ·  Posted

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

 

1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#9 ·  Posted

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?

Share this post


Link to post
Share on other sites

#10 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#11 ·  Posted

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()

Share this post


Link to post
Share on other sites

#12 ·  Posted

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0