Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

Install font batch file and vbscript

In batch file script the first below line copies myFont.ttf into Windows font directory, and the second line registers it into Registry.

XCOPY "myFont.ttf" "C:WindowsFonts"
REG add "HKLMSOFTWAREMicrosoftWindows NTCurrentVersionFonts" /v "myFont (TrueType)" /t REG_SZ /d myFont.ttf /f

An application sends the WM_FONTCHANGE message to all top-level windows in the system after changing the pool of font resources.

To send this message, call the SendMessage function with the following parameters.

following code is in VB programming language but I need to send WM_FONTCHANGE using SendMessage function in batch file script or at least vbscript, But I don't know how do it in batch file script, If you know help me please, thanks.

Private Const HWND_BROADCAST = &HFFFF&
Private Const WM_FONTCHANGE = &H1D
Private Declare Function AddFontResource Lib "gdi32" Alias "AddFontResourceA" (ByVal lpFileName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub Form_Load()
    Dim res As Long
    res = AddFontResource("C:FontsNordic__.ttf")
    If res > 0 Then
        SendMessage HWND_BROADCAST, WM_FONTCHANGE, 0, 0
        MsgBox res & " fonts were added!"
    End If
End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Finally I found the solution, special thank to JosefZ, as he said Powershell is the solution, All you need is download and copy Add-font.ps1 by Michael Murgolo to your project folder and copy below lines into your batch file:

@echo off
PowerShell Set-ExecutionPolicy RemoteSigned
PowerShell -command "& '%~dp0Add-Font.ps1' -path '%~dp0myFont.ttf'"

Note you must run this script as Administrator, hence you need to add %~dp0 before your files.

Thats all, you even don't need the codes in my question, good luck.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...