在不注销的情况下启用/禁用 ClearType [英] Enable/disable ClearType without logging out

查看:86
本文介绍了在不注销的情况下启用/禁用 ClearType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过 cmd(或任何脚本,如 VBS/JS)或从注册表无需注销或重新启动 Windows.

I need to enable/disable ClearType (or "Adjust the appearance and performance of Windows > Smooth edges of screen fonts") via cmd (or any script like VBS/JS) or from the registry without logging out or restarting Windows.

也许可以只为一个应用程序启用 ClearType.

Maybe it's possible to enable ClearType only for one application.

推荐答案

Windows 下的现代脚本编写方式是使用 PowerShell.以下脚本需要 2.0 版,可从 Windows XP SP3 获得:

The modern way of scripting under Windows is using PowerShell. The following script requires version 2.0, which is available from Windows XP SP3:

#requires -version 2.0
param([bool]$enable)

$signature = @'
[DllImport("user32.dll")]
public static extern bool SystemParametersInfo(
    uint uiAction,
    uint uiParam,
    uint pvParam,
    uint fWinIni);
'@

$SPI_SETFONTSMOOTHING      = 0x004B
$SPI_SETFONTSMOOTHINGTYPE  = 0x200B
$SPIF_UPDATEINIFILE        = 0x1
$SPIF_SENDCHANGE           = 0x2
$FE_FONTSMOOTHINGCLEARTYPE = 0x2

$winapi = Add-Type -MemberDefinition $signature -Name WinAPI -PassThru

if ($enable)
{
    [void]$winapi::SystemParametersInfo($SPI_SETFONTSMOOTHING, 1, 0, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
    [void]$winapi::SystemParametersInfo($SPI_SETFONTSMOOTHINGTYPE, 0, $FE_FONTSMOOTHINGCLEARTYPE, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
}
else
{
    [void]$winapi::SystemParametersInfo($SPI_SETFONTSMOOTHING, 0, 0, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
}

如果由于某种原因无法使用 PowerShell,则需要 DynamicWrapperX 为了在 WSH 中执行 WinAPI 函数.您首先需要在目标机器上注册它,然后才能使用这个 VBScript:

If, for some reason, you can't use PowerShell, you'll need DynamicWrapperX in order to execute WinAPI functions in WSH. You will first need to register it on the target machine, then you could use this VBScript:

Set WinAPI = CreateObject("DynamicWrapperX")
WinAPI.Register "user32.dll", "SystemParametersInfo", "i=uuuu"

Const SPI_SETFONTSMOOTHING      = &H004B
Const SPI_SETFONTSMOOTHINGTYPE  = &H200B
Const SPIF_UPDATEINIFILE        = &H1
Const SPIF_SENDCHANGE           = &H2
Const FE_FONTSMOOTHINGCLEARTYPE = &H2

If WScript.Arguments(0) Then
    WinAPI.SystemParametersInfo SPI_SETFONTSMOOTHING, 1, 0, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE
    WinAPI.SystemParametersInfo SPI_SETFONTSMOOTHINGTYPE, 0, FE_FONTSMOOTHINGCLEARTYPE, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE
Else
    WinAPI.SystemParametersInfo SPI_SETFONTSMOOTHING, 0, 0, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE
End If

两个脚本都接受一个参数,0 表示禁用 ClearType,1 表示启用.无需重启.

Both scripts accept one parameter, 0 means disable ClearType, 1 means enable. No reboot is needed.

这篇关于在不注销的情况下启用/禁用 ClearType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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