本帖最后由 vszy 于 2012-11-14 00:37 编辑
今天进来想找个自动批量安装字体的脚本,结果找到
http://www.autoitx.com/forum.php ... C%E5%2B%B0%B2%D7%B0
http://www.autoitx.com/forum.php ... C%E5%2B%B0%B2%D7%B0
试用一下效果不是理想,有的不支持Win7,有的需重启生效。于是官网BBS找到这个帖子。
http://www.autoitscript.com/foru ... l__+font%20+install
在这里找到一段源码:
InstallFont(@ScriptDir&"\*.*")
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
第一行改过,目前个人测试XP,WIN7均能正常安装,且不用重启即可使用新装的字体。向WINDOWS系统自带安装后一样。
就是本人英文很菜,不知道复制这段代码是不是那帖子中最终代码。望大家帮忙测试。有懂英文的帮看看还有更完善的代码没。(发帖时都忘记自己复制的是哪段了,哈哈) |