安装字体的批处理文件和VBScript [英] Install font batch file and vbscript

查看:1054
本文介绍了安装字体的批处理文件和VBScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在批处理文件脚本中的第一线下方副本myFont.ttf到Windows字体目录,第二行它注册到注册表中。

  XCOPYmyFont.ttfC:\\ WINDOWS \\字体
REG ADDHKLM \\ SOFTWARE \\微软\\的Windows NT \\ CURRENTVERSION \\字体/ VmyFont(TrueType字体)/吨REG_SZ / d的myFont.ttf /˚F

应用程序更改字体的资源池后发送WM_FONTCHANGE消息系统中的所有顶级窗口。

要使用下面的参数发送此消息,调用SendMessage函数。

以下code是在VB编程语言,但我需要在批处理文件脚本或者至少VBScript中使用SendMessage函数来发送WM_FONTCHANGE,但我不知道怎么在批处理文件脚本做到这一点,如果你知道帮我请,谢谢。

 私人常量HWND_BROADCAST =安培; HFFFF&安培;
私人常量WM_FONTCHANGE =安培; H1D
私人声明函数AddFontResource库GDI32别名AddFontResourceA(BYVAL lpFileName的对象作为字符串)只要
私人声明函数库SendMessage函数USER32别名SendMessageA(BYVAL HWND长,BYVAL WMSG长,BYVAL的wParam长,lParam中任意)只要私人小组的Form_Load()
    昏暗的资源,只要
    RES = AddFontResource(C:\\字体\\ __北欧TTF)
    如果解析度> 0,则
        的SendMessage HWND_BROADCAST,WM_FONTCHANGE,0,0
        MSGBOX资源和放大器; 添加字体!
    万一
结束小组


解决方案

我终于找到了解决办法,特别感谢到 JosefZ ,就像他说的PowerShell是该解决方案,您只需要下载和复制<一个href=\"https://blogs.technet.microsoft.com/deploymentguys/2010/12/04/adding-and-removing-fonts-with-windows-powershell/\"相对=nofollow>添加-font.ps1由迈克尔Murgolo 到项目文件夹,并复制以下行到您的批处理文件:

 关闭@echo
PowerShell中的Set-ExecutionPolicy RemoteSigned就是
PowerShell的-command&放大器;'%〜dp0Add-Font.ps1-path'%〜dp0myFont.ttf'

请注意,您必须运行此脚本以管理员身份,因此,你需要你的文件之前添加%〜DP0。

这就是所有,你甚至不需要codeS在我的问题,祝你好运。

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:\Windows\Fonts"
REG add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /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:\Fonts\Nordic__.ttf")
    If res > 0 Then
        SendMessage HWND_BROADCAST, WM_FONTCHANGE, 0, 0
        MsgBox res & " fonts were added!"
    End If
End Sub

解决方案

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.

这篇关于安装字体的批处理文件和VBScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆