Jump to content

Automatically install Fonts in Windows 7


Recommended Posts

I am trying to get a script working, installing a font (3 Files - Normal, Italic, bold)

In the template script, the name it set, was generated automatically, by reading the .ttf files. But I changed it because it used to set the Registry keys with german "Names". When installing manually, it's setting them in english as I entered in the script.

But now, it doesn't even set the RegKeys...

#Include <WinAPIEx.au3>
ConsoleWrite(_FontInstall1('letgot.ttf') & @CR)
ConsoleWrite(_FontInstall2('letgotb.ttf') & @CR)
ConsoleWrite(_FontInstall3('letgoti.ttf') & @CR)
Func _FontInstall1($sFile)
    Local $Font, $Name, $Path
$CSIDL_FONTS = "C:\Windows\Fonts"
$Name = "Letter Gothic (TrueType)"
$Font = "letgot.ttf"
    If Not RegWrite('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', $Name, 'REG_SZ', $Font) Then
        Return SetError(2, 0, 0)
    EndIf
    $Path = @WindowsDir & "\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, 1) Then
        Return SetError(4, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_FontInstall
Func _FontInstall2($sFile)
    Local $Font, $Name, $Path
$CSIDL_FONTS = "C:\Windows\Fonts"
$Name = "Letter Gothic Bold (TrueType)"
$Font = "letgotb.ttf"
    If Not RegWrite('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', $Name, 'REG_SZ', $Font) Then
        Return SetError(2, 0, 0)
    EndIf
    $Path = @WindowsDir & "\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, 1) Then
        Return SetError(4, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_FontInstall
Func _FontInstall3($sFile)
    Local $Font, $Name, $Path
$CSIDL_FONTS = "C:\Windows\Fonts"
$Name = "Letter Gothic Italic (TrueType)"
$Font = "letgoti.ttf"
    If Not RegWrite('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', $Name, 'REG_SZ', $Font) Then
        Return SetError(2, 0, 0)
    EndIf
    $Path = @WindowsDir & "\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, 1) Then
        Return SetError(4, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_FontInstall
Link to comment
Share on other sites

First, make sure that the script is running with administrator privileges. Second, use the _WinAPI_GetFontResourceInfo() function to retrieve the names of the font. Third, to set the font to the "Fonts" folder you can simply copy it (no need modify registry).

Link to comment
Share on other sites

First, make sure that the script is running with administrator privileges. Second, use the _WinAPI_GetFontResourceInfo() function to retrieve the names of the font. Third, to set the font to the "Fonts" folder you can simply copy it (no need modify registry).

Running with administrator privileges doesn't help - There are still no Reg Entries.

I don't use the WinAPI because it returns different Names than when i install it manually (it returns german names).

So - you think i can simply run Filecopy ($font, "C:WindowsFonts")? Wish it was that simple...

Link to comment
Share on other sites

I used Yashied's WinAPIEx UDF. Here:

#Include <APIConstants.au3>
#Include <StaticConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
FileCopy("myfont.ttf", @WindowsDir & "Fonts")
_WinAPI_AddFontResourceEx(@WindowsDir & 'Fontsmyfont.ttf', $FR_PRIVATE, 1)

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

I made my own version of this...

#Include <APIConstants.au3>
#Include <StaticConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Local $i
Local $f=0
Local $suc
Local $nr
Local $Name[3]
$Name[0]="letgot.ttf"
$Name[1]="letgotb.ttf"
$Name[2]="letgoti.ttf"
For $i In $Name
$suc = FileCopy($i, @WindowsDir & "Fonts")
$nr = _WinAPI_AddFontResourceEx(@WindowsDir & 'Fonts' & $i, $FR_PRIVATE, 1)
  If $suc = 0 Then
   MsgBox(16,"Failed", "Import of the file " & $i & " failed.")
   $f=$f+1
  EndIf
Next
If $f<1 Then
MsgBox(16,"Succeeded", "Import of "&$nr&" files succeeded.")
EndIf

But it doesn't work, although I'm running it as a local administrator.

All 3 fonts keep failing on the filecopy part.

Link to comment
Share on other sites

If FileCopy doesn't work for you, why don't you try the xcopy utility (using Run function)?

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

  • 2 months later...

I used Yashied's WinAPIEx UDF. Here:

#Include <APIConstants.au3>
#Include <StaticConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
FileCopy("myfont.ttf", @WindowsDir & "Fonts")
_WinAPI_AddFontResourceEx(@WindowsDir & 'Fontsmyfont.ttf', $FR_PRIVATE, 1)

did this work on Win7 32bit? I am trying to use this same code to try to install a bunch of older barcode ttf fonts but have not been able to get this to even copy the fonts. i modified the script to include myfont.ttf = C39EI.ttf (the name of the font file i want to install). i also have installed the WinAPIEx UDF addon into my autoit v3 install too.. I actually build .exe files of the scripts which are then ran as the user account. I even tried to compile a second .exe to run the above script built into an exe as the local administrator w/o any luck. no registry entries and the font file never gets copied to C:\windows\fonts

any help would be much appreciated. btw, i love autoit for app deployments! makes our lives so much easier!

Link to comment
Share on other sites

There was a minor mistake in the previous script:

#Include <APIConstants.au3>
#Include <StaticConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
FileCopy("myfont.ttf", @WindowsDir & "Fonts")
_WinAPI_AddFontResourceEx(@WindowsDir & 'Fontsmyfont.ttf', $FR_PRIVATE, 1)

I think it could work now.

Edited by MKISH

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

I've tried to run the small script above but get the error that the APIConstants cannot be found.

I use AutoIT on the odd basis to create scripts for installing software etc for users. Been doing this for 4+ years now so it will be something silly I'm not doing that you guys just do on a regular basis.

Just downloaded the latest version in case the Include files were there.

Any help appreciated as I'm trying to get some otf files installed as fonts.

Paul

Link to comment
Share on other sites

  • 1 year later...

This worked for me on W7

note that @WindowsDir return the path with no "" at the end. you must include that at the beginning of the "Fonts" folder.

#Include <APIConstants.au3>
#Include <StaticConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)

dim $font, $source
$source="\\server\Apps\NewInstalls\fonts\AllFonts\" ; plug the location of you fonts

FileCopy($source&'addict.ttf', @WindowsDir & "\Fonts",1)
$font = @WindowsDir & '\Fonts\ADDICT.TTF'
 _WinAPI_AddFontResourceEx($font)
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...