Vale9999 Posted May 31, 2012 Share Posted May 31, 2012 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... expandcollapse popup#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 More sharing options...
Yashied Posted May 31, 2012 Share Posted May 31, 2012 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). My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Vale9999 Posted May 31, 2012 Author Share Posted May 31, 2012 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 More sharing options...
stormbreaker Posted May 31, 2012 Share Posted May 31, 2012 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 More sharing options...
Vale9999 Posted May 31, 2012 Author Share Posted May 31, 2012 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 More sharing options...
stormbreaker Posted May 31, 2012 Share Posted May 31, 2012 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 More sharing options...
jamesselix Posted August 15, 2012 Share Posted August 15, 2012 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 More sharing options...
stormbreaker Posted August 17, 2012 Share Posted August 17, 2012 (edited) 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 August 17, 2012 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 More sharing options...
Langy Posted August 21, 2012 Share Posted August 21, 2012 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 More sharing options...
Kurgan Posted April 9, 2014 Share Posted April 9, 2014 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) xuanguang 1 Link to comment Share on other sites More sharing options...
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