Jump to content



Photo

Font install


  • Please log in to reply
14 replies to this topic

#1 skyee

skyee

    Seeker

  • Active Members
  • 10 posts

Posted 23 January 2008 - 11:50 AM

This is the current font install script:
$sFileName = '\\server.local\Software\_Install\_Default\1\CORPORATE FONT\*.*'             If FileCopy($sFileName, @WindowsDir & '\Fonts',1) Then             $sFileName = @WindowsDir & '\Fonts\' & StringTrimLeft($sFileName, StringInStr($sFileName, '\', 0, -1))             DllCall('gdi32', 'long', "AddFontResourceA", 'String', $sFileName)             EndIf


The fonts get copied, however they're not registred with system when I try to use them in i.e. MS Word. What else needs to be done? :D





#2 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,241 posts

Posted 23 January 2008 - 12:19 PM

Hi,

This function should work (not mine, i just modified a little)...

Func InstallFont($sSourceFile, $sFontDescription, $sFontsPath)     Local Const $HWND_BROADCAST = 0xFFFF     Local Const $WM_FONTCHANGE = 0x1D         Local $sFontFileName = StringRegExpReplace($sSourceFile, '^.*\\', '')     If Not FileCopy($sSourceFile, $sFontsPath & "\" & $sFontFileName, 1) Then Return SetError(1, 0, 0)         Local $aRet = DllCall("gdi32.dll", "Int", "AddFontResource", "str", @WindowsDir & "\fonts\" & $sFontFileName)     If IsArray($aRet) And $aRet[0] > 0 Then         RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $sFontDescription, "REG_SZ", $sFontFileName)         DllCall("user32.dll", "Int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_FONTCHANGE, "int", 0, "int", 0)         Return 1     EndIf     Return SetError(2, 0, 0) EndFunc

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#3 skyee

skyee

    Seeker

  • Active Members
  • 10 posts

Posted 23 January 2008 - 12:29 PM

Hi,

This function should work (not mine, i just modified a little)...

Func InstallFont($sSourceFile, $sFontDescription, $sFontsPath)     Local Const $HWND_BROADCAST = 0xFFFF     Local Const $WM_FONTCHANGE = 0x1D         Local $sFontFileName = StringRegExpReplace($sSourceFile, '^.*\\', '')     If Not FileCopy($sSourceFile, $sFontsPath & "\" & $sFontFileName, 1) Then Return SetError(1, 0, 0)         Local $aRet = DllCall("gdi32.dll", "Int", "AddFontResource", "str", @WindowsDir & "\fonts\" & $sFontFileName)     If IsArray($aRet) And $aRet[0] > 0 Then         RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $sFontDescription, "REG_SZ", $sFontFileName)         DllCall("user32.dll", "Int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_FONTCHANGE, "int", 0, "int", 0)         Return 1     EndIf     Return SetError(2, 0, 0) EndFunc

Do you mind modifying this to enter source of my fonts? (\\server.local\Software\_Install\_Default\1\CORPORATE FONT\) since I admit have no clue where to put source from where script will get fonts?

#4 skyee

skyee

    Seeker

  • Active Members
  • 10 posts

Posted 23 January 2008 - 01:18 PM

Do you mind modifying this to enter source of my fonts? (\\server.local\Software\_Install\_Default\1\CORPORATE FONT\) since I admit have no clue where to put source from where script will get fonts?

I tried this:

Func InstallFont($sSourceFile, $sFontDescription, $sFontsPath)     Local Const $HWND_BROADCAST = 0xFFFF     Local Const $WM_FONTCHANGE = 0x1D     Local $sFontsPath = "\\server.local\Software\_Install\_Default\1\CORPORATE FONT\"     Local $sFontFileName = StringRegExpReplace($sSourceFile, '^.*\\', '')     If Not FileCopy($sSourceFile, $sFontsPath & "\" & $sFontFileName, 1) Then Return SetError(1, 0, 0)         Local $aRet = DllCall("gdi32.dll", "Int", "AddFontResource", "str", @WindowsDir & "\fonts\" & $sFontFileName)     If IsArray($aRet) And $aRet[0] > 0 Then         RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $sFontDescription, "REG_SZ", $sFontFileName)         DllCall("user32.dll", "Int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_FONTCHANGE, "int", 0, "int", 0)         Return 1     EndIf     Return SetError(2, 0, 0) EndFunc

But it doesn't work :P I would _really_ like someone to help me out here.. Fonts just dont seem to install. And I'm a script noobie :D

#5 skyee

skyee

    Seeker

  • Active Members
  • 10 posts

Posted 23 January 2008 - 02:58 PM

Anyone? :D

#6 Jos

Jos

    oh joy ...

  • Developers
  • 21,037 posts

Posted 23 January 2008 - 03:08 PM

I guess it should be something like this (untested):

InstallFont('\\server.local\Software\_Install\_Default\1\CORPORATE FONT\fontname.ttf',"font description") Func InstallFont($sSourceFile, $sFontDescription)     Local Const $HWND_BROADCAST = 0xFFFF     Local Const $WM_FONTCHANGE = 0x1D         Local $sFontFileName = StringRegExpReplace($sSourceFile, '^.*\\', '')     If Not FileCopy($sSourceFile, @WindowsDir & "\fonts\" & $sFontFileName, 1) Then Return SetError(1, 0, 0)         Local $aRet = DllCall("gdi32.dll", "Int", "AddFontResource", "str", @WindowsDir & "\fonts\" & $sFontFileName)     If IsArray($aRet) And $aRet[0] > 0 Then         RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $sFontDescription, "REG_SZ", $sFontFileName)         DllCall("user32.dll", "Int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_FONTCHANGE, "int", 0, "int", 0)         Return 1     EndIf     Return SetError(2, 0, 0) EndFunc


:D

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 [color=#ff0000;] [/color][color=#ff0000;]ForumRules[/color]

 

[color=#0000cd;]Live for the present,
Dream of the future,
Learn from the past.
[/color]
  :)


#7 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,241 posts

Posted 23 January 2008 - 03:31 PM

I changed the function, so now it can install more then one font (if passing wildcard as file name)...

AutoIt         
InstallFont("\\server.local\Software\_Install\_Default\1\CORPORATE FONT\*.*") Func InstallFont($sSourceFile, $sFontDescript="", $sFontsPath="")     Local Const $HWND_BROADCAST = 0xFFFF     Local Const $WM_FONTCHANGE = 0x1D         If $sFontsPath = "" Then $sFontsPath = @WindowsDir & "\fonts"         Local $sFontName = StringRegExpReplace($sSourceFile, "^.*\\", "")     If Not FileCopy($sSourceFile, $sFontsPath & "\" & $sFontName, 1) Then Return SetError(1, 0, 0)         Local $hSearch = FileFindFirstFile($sSourceFile)     Local $iFontIsWildcard = StringRegExp($sFontName, "\*|\?")     Local $aRet, $hGdi32_DllOpen = DllOpen("gdi32.dll")         If $hSearch = -1 Then Return SetError(2, 0, 0)     If $hGdi32_DllOpen = -1 Then Return SetError(3, 0, 0)         While 1         $sFontName = FileFindNextFile($hSearch)         If @error Then ExitLoop                 If $iFontIsWildcard Then $sFontDescript = StringRegExpReplace($sFontName, "\.[^\.]*$", "")                 $aRet = DllCall($hGdi32_DllOpen, "Int", "AddFontResource", "str", $sFontsPath & "\" & $sFontName)         If IsArray($aRet) And $aRet[0] > 0 Then             RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", _                 $sFontDescript, "REG_SZ", $sFontsPath & "\" & $sFontName)         EndIf     WEnd         DllClose($hGdi32_DllOpen)     DllCall("user32.dll", "Int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_FONTCHANGE, "int", 0, "int", 0)     Return 1 EndFunc


Edit: changed to DllOpen mode.
Edit 2: Added full path writing (to registry), in case that we want to install font to other path then @WindowsDir\fonts.

Edited by MsCreatoR, 23 January 2008 - 03:41 PM.

  • IgImAx likes this
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#8 skyee

skyee

    Seeker

  • Active Members
  • 10 posts

Posted 25 January 2008 - 07:56 AM

I changed the function, so now it can install more then one font (if passing wildcard as file name)...

AutoIt         
InstallFont("\\server.local\Software\_Install\_Default\1\CORPORATE FONT\*.*") Func InstallFont($sSourceFile, $sFontDescript="", $sFontsPath="")     Local Const $HWND_BROADCAST = 0xFFFF     Local Const $WM_FONTCHANGE = 0x1D         If $sFontsPath = "" Then $sFontsPath = @WindowsDir & "\fonts"         Local $sFontName = StringRegExpReplace($sSourceFile, "^.*\\", "")     If Not FileCopy($sSourceFile, $sFontsPath & "\" & $sFontName, 1) Then Return SetError(1, 0, 0)         Local $hSearch = FileFindFirstFile($sSourceFile)     Local $iFontIsWildcard = StringRegExp($sFontName, "\*|\?")     Local $aRet, $hGdi32_DllOpen = DllOpen("gdi32.dll")         If $hSearch = -1 Then Return SetError(2, 0, 0)     If $hGdi32_DllOpen = -1 Then Return SetError(3, 0, 0)         While 1         $sFontName = FileFindNextFile($hSearch)         If @error Then ExitLoop                 If $iFontIsWildcard Then $sFontDescript = StringRegExpReplace($sFontName, "\.[^\.]*$", "")                 $aRet = DllCall($hGdi32_DllOpen, "Int", "AddFontResource", "str", $sFontsPath & "\" & $sFontName)         If IsArray($aRet) And $aRet[0] > 0 Then             RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", _                 $sFontDescript, "REG_SZ", $sFontsPath & "\" & $sFontName)         EndIf     WEnd         DllClose($hGdi32_DllOpen)     DllCall("user32.dll", "Int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_FONTCHANGE, "int", 0, "int", 0)     Return 1 EndFunc

Edit: changed to DllOpen mode.
Edit 2: Added full path writing (to registry), in case that we want to install font to other path then @WindowsDir\fonts.

Excellent work! Thank you so much :D

#9 Ármányos Kő

Ármányos Kő

    Wayfarer

  • Active Members
  • Pip
  • 72 posts

Posted 13 February 2008 - 01:14 AM

I changed the function, so now it can install more then one font (if passing wildcard as file name)...

AutoIt         
InstallFont("\\server.local\Software\_Install\_Default\1\CORPORATE FONT\*.*") Func InstallFont($sSourceFile, $sFontDescript="", $sFontsPath="")     Local Const $HWND_BROADCAST = 0xFFFF     Local Const $WM_FONTCHANGE = 0x1D         If $sFontsPath = "" Then $sFontsPath = @WindowsDir & "\fonts"         Local $sFontName = StringRegExpReplace($sSourceFile, "^.*\\", "")     If Not FileCopy($sSourceFile, $sFontsPath & "\" & $sFontName, 1) Then Return SetError(1, 0, 0)         Local $hSearch = FileFindFirstFile($sSourceFile)     Local $iFontIsWildcard = StringRegExp($sFontName, "\*|\?")     Local $aRet, $hGdi32_DllOpen = DllOpen("gdi32.dll")         If $hSearch = -1 Then Return SetError(2, 0, 0)     If $hGdi32_DllOpen = -1 Then Return SetError(3, 0, 0)         While 1         $sFontName = FileFindNextFile($hSearch)         If @error Then ExitLoop                 If $iFontIsWildcard Then $sFontDescript = StringRegExpReplace($sFontName, "\.[^\.]*$", "")                 $aRet = DllCall($hGdi32_DllOpen, "Int", "AddFontResource", "str", $sFontsPath & "\" & $sFontName)         If IsArray($aRet) And $aRet[0] > 0 Then             RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", _                 $sFontDescript, "REG_SZ", $sFontsPath & "\" & $sFontName)         EndIf     WEnd         DllClose($hGdi32_DllOpen)     DllCall("user32.dll", "Int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_FONTCHANGE, "int", 0, "int", 0)     Return 1 EndFunc

Edit: changed to DllOpen mode.
Edit 2: Added full path writing (to registry), in case that we want to install font to other path then @WindowsDir\fonts.

This is excellent!
How would the deinstalling look like? I tried many basic things (deleting from font directory...), but surely they did not work.
I need to do something like Suitcase does on Mac.

#10 bluespirit

bluespirit

    Seeker

  • Active Members
  • 9 posts

Posted 12 June 2008 - 09:27 PM

Hi,

I'm trying to extract the font name out of a .ttf file to enter the correct info into the registry. Anyone know how to do this?

I'm installing the fonts using the AddFontResource DLL call, Registry write and SendMessage DLL call method as described below. However, this relies on you already knowing the font name. I was also going to rename the .ttf file with the full name before installing.

The best I've managed to find is a GetFontName function by Holger but this only works once the font is already installed or in memory.


Thanks for any help,
James

#11 DangerousDan

DangerousDan

    Seeker

  • Active Members
  • 44 posts

Posted 24 June 2008 - 05:14 PM

nice find, I am adding this later since I have been trying to use fileinstall by itself. new to scripting as well and this autoit thing is aswesome!

I usually veiw the files from the dos prompt to get actual file names...

#12 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 24 June 2008 - 06:11 PM

Here is a full install routine for TTF fonts in VB : http://www.codeguru.com/vb/gen/vb_system/w...icle.php/c1659/
Basically, a .FOT font resource is created and installed. From this, the font name is being extracted :)

Edited by ProgAndy, 24 June 2008 - 06:12 PM.

*GERMAN* Posted Image [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

#13 DangerousDan

DangerousDan

    Seeker

  • Active Members
  • 44 posts

Posted 02 July 2008 - 02:04 PM

are you guys having to restart after using this function to install a font? I am... :)

#14 jennico

jennico

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 862 posts

Posted 09 April 2009 - 01:29 AM

very nice work ! thx. j. :D
I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Posted ImageDon't forget this IP: 213.251.145.96

#15 Myicq

Myicq

    Prodigy

  • Active Members
  • PipPipPip
  • 166 posts

Posted 20 June 2012 - 10:05 AM

How would the deinstalling look like? I tried many basic things (deleting from font directory...), but surely they did not work.

I have not tried this, but guess that mostly same code can be used.
You have
BOOL RemoveFontResource(   __in  LPCTSTR lpFileName );
See: http://msdn.microsoft.com/en-us/library/windows/desktop/dd162922%28v=vs.85%29.aspx

My steps would be
  • From registry find full path name(s)
  • Call above DLL
  • Remove registry entry
  • Delete file
  • Send broadcast message WM_FONTCHANGE
Not sure if you need to use RemoveFontResource or RemoveFontResource[A|W] for Ansi/Unicode.
Code from MrCreator should be simple to modify.

Good luck.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users