skyee Posted January 23, 2008 Posted January 23, 2008 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?
MrCreatoR Posted January 23, 2008 Posted January 23, 2008 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 Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler 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 ProgramUDFs: 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 UDF 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 Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
skyee Posted January 23, 2008 Author Posted January 23, 2008 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?
skyee Posted January 23, 2008 Author Posted January 23, 2008 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 I would _really_ like someone to help me out here.. Fonts just dont seem to install. And I'm a script noobie
Developers Jos Posted January 23, 2008 Developers Posted January 23, 2008 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 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
MrCreatoR Posted January 23, 2008 Posted January 23, 2008 (edited) I changed the function, so now it can install more then one font (if passing wildcard as file name)...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 EndFuncEdit: 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 January 23, 2008 by MsCreatoR IgImAx 1 Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler 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 ProgramUDFs: 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 UDF 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 Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
skyee Posted January 25, 2008 Author Posted January 25, 2008 I changed the function, so now it can install more then one font (if passing wildcard as file name)... 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
Ármányos Kő Posted February 13, 2008 Posted February 13, 2008 I changed the function, so now it can install more then one font (if passing wildcard as file name)... 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.
bluespirit Posted June 12, 2008 Posted June 12, 2008 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
DangerousDan Posted June 24, 2008 Posted June 24, 2008 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...
ProgAndy Posted June 24, 2008 Posted June 24, 2008 (edited) 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 June 24, 2008 by ProgAndy *GERMAN* [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
DangerousDan Posted July 2, 2008 Posted July 2, 2008 are you guys having to restart after using this function to install a font? I am...
jennico Posted April 9, 2009 Posted April 9, 2009 very nice work ! thx. j. Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96
Myicq Posted June 20, 2012 Posted June 20, 2012 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 beFrom registry find full path name(s)Call above DLLRemove registry entryDelete fileSend broadcast message WM_FONTCHANGENot sure if you need to use RemoveFontResource or RemoveFontResource[A|W] for Ansi/Unicode. Code from MrCreator should be simple to modify. Good luck. I am just a hobby programmer, and nothing great to publish right now.
Silverback83 Posted March 29, 2017 Posted March 29, 2017 I know this is a very old topic, but rather than start a new one its best I just reply to this? Post #9 doesnt work for me. (Obv replacing the server directory with my own. It seems to do nothing. Is that because the code no longer works due to different syntax in newer versions of autoit or possibly another reason? I'm simply trying to auto install a folder of fonts using a script like shown in post #9 I get Exit Code 0 which Google tells is a success expect nothing happens.
Moderators Melba23 Posted March 29, 2017 Moderators Posted March 29, 2017 Silverback83, Quote I know this is a very old topic, but rather than start a new one its best I just reply to this? No, we prefer that you open a new thread and link to the old one if required. As the code you are trying to run dates from some 9 years ago I am not at all surprised that it does not run under the current release. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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