无需注销即可启用/禁用 ClearType

发布于 2024-11-01 17:59:51 字数 164 浏览 0 评论 0原文

我需要通过 cmd (或任何类似 VBS/JS 的脚本)或从注册表启用/禁用 ClearType(或“调整 Windows 的外观和性能 > 屏幕字体的平滑边缘”)无需注销或重新启动Windows。

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

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

夏夜暖风 2024-11-08 17:59:51

Windows 下脚本编写的现代方法是使用 PowerShell。以下脚本需要版本 2.0,可从 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:

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 表示启用。无需重新启动。

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)
}

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

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

少钕鈤記 2024-11-08 17:59:51

为了添加更多选项,我有 C# 版本,并添加了 GetFontSmoothing。

    [DllImport("user32.dll", SetLastError = true)]
    static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int pvParam, uint fWinIni);

    const uint SPI_GETFONTSMOOTHING = 74;
    const uint SPI_SETFONTSMOOTHING = 75;
    const uint SPI_UPDATEINI = 0x1;
    const UInt32 SPIF_UPDATEINIFILE = 0x1;

    private Boolean GetFontSmoothing()
    {
        bool iResult;
        int pv = 0;
        /* Call to systemparametersinfo to get the font smoothing value. */
        iResult = SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, ref pv, 0);
        if (pv > 0)
        {
            //pv > 0 means font smoothing is on.
            return true;
        }
        else
        {
            //pv == 0 means font smoothing is off.
            return false;
        }
    }

    private void DisableFontSmoothing()
    {
        bool iResult;
        int pv = 0;
        /* Call to systemparametersinfo to set the font smoothing value. */
        iResult = SystemParametersInfo(SPI_SETFONTSMOOTHING, 0, ref pv, SPIF_UPDATEINIFILE);
        Console.WriteLine("Disabled: {0}", iResult);
    }

    private void EnableFontSmoothing()
    {
        bool iResult;
        int pv = 0;
        /* Call to systemparametersinfo to set the font smoothing value. */
        iResult = SystemParametersInfo(SPI_SETFONTSMOOTHING, 1, ref pv, SPIF_UPDATEINIFILE);
        Console.WriteLine("Enabled: {0}", iResult);
    }

Just to add more options, I have the C# version, adding GetFontSmoothing to it.

    [DllImport("user32.dll", SetLastError = true)]
    static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int pvParam, uint fWinIni);

    const uint SPI_GETFONTSMOOTHING = 74;
    const uint SPI_SETFONTSMOOTHING = 75;
    const uint SPI_UPDATEINI = 0x1;
    const UInt32 SPIF_UPDATEINIFILE = 0x1;

    private Boolean GetFontSmoothing()
    {
        bool iResult;
        int pv = 0;
        /* Call to systemparametersinfo to get the font smoothing value. */
        iResult = SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, ref pv, 0);
        if (pv > 0)
        {
            //pv > 0 means font smoothing is on.
            return true;
        }
        else
        {
            //pv == 0 means font smoothing is off.
            return false;
        }
    }

    private void DisableFontSmoothing()
    {
        bool iResult;
        int pv = 0;
        /* Call to systemparametersinfo to set the font smoothing value. */
        iResult = SystemParametersInfo(SPI_SETFONTSMOOTHING, 0, ref pv, SPIF_UPDATEINIFILE);
        Console.WriteLine("Disabled: {0}", iResult);
    }

    private void EnableFontSmoothing()
    {
        bool iResult;
        int pv = 0;
        /* Call to systemparametersinfo to set the font smoothing value. */
        iResult = SystemParametersInfo(SPI_SETFONTSMOOTHING, 1, ref pv, SPIF_UPDATEINIFILE);
        Console.WriteLine("Enabled: {0}", iResult);
    }
_失温 2024-11-08 17:59:51

Python版本:

# make sure you install pywin32 
# from http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/
import win32con
import win32gui

win32gui.SystemParametersInfo(win32con.SPI_SETFONTSMOOTHING, True, 0) # enable only
win32gui.SystemParametersInfo(win32con.SPI_SETFONTSMOOTHINGTYPE,
        win32con.FE_FONTSMOOTHINGCLEARTYPE,
        win32con.SPIF_UPDATEINIFILE | win32con.SPIF_SENDCHANGE)

Python version:

# make sure you install pywin32 
# from http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/
import win32con
import win32gui

win32gui.SystemParametersInfo(win32con.SPI_SETFONTSMOOTHING, True, 0) # enable only
win32gui.SystemParametersInfo(win32con.SPI_SETFONTSMOOTHINGTYPE,
        win32con.FE_FONTSMOOTHINGCLEARTYPE,
        win32con.SPIF_UPDATEINIFILE | win32con.SPIF_SENDCHANGE)
标点 2024-11-08 17:59:51

制作扩展名为 .reg 的文件,这是文件的注册表

Disable_Smooth_edges_of_screen_fonts

[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="0"

Enable_Smooth_edges_of_screen_fonts

[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="2"

您也可以通过 cmd 执行此操作
这是命令的语法,

REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d Data] [/f]

您必须注销才能使更改生效

make file with extention .reg this is registry for files

Disable_Smooth_edges_of_screen_fonts

[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="0"

Enable_Smooth_edges_of_screen_fonts

[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="2"

you can also do this vis cmd
here is syntax for command

REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d Data] [/f]

you must logoff to have effect that you changed

心房的律动 2024-11-08 17:59:51

我不知道如何在不重新启动的情况下做到这一点...

但我发现更改 FontSmoothing 键根本不够...

有关如何完全删除 ClearType 和 FontSmoothing 的完整过程,请查看:

完全禁用字体平滑和 Windows 7 中的 ClearType

I'm not sure how to do it without Rebooting...

But i found that changing the FontSmoothing keys was simply not enough...

For a full procedure on how to completely remove ClearType and FontSmoothing, check this out:

Completley Disable Font Smoothing and ClearType in Windows 7

苏大泽ㄣ 2024-11-08 17:59:51

以下对我有用:
控制面板>系统>高级系统设置>>高级> (性能)设置>视觉效果>选择“自定义”并取消选中“屏幕字体的平滑边缘”

The following works for me:
Control Panel > System > Advanced system settings > Advanced > (Performance) Settings > Visual Effects > Select 'Custom' and uncheck 'Smooth edges of screen fonts'

只涨不跌 2024-11-08 17:59:51

查看以下链接中描述的内容:

http://www.vbforums.com/showthread .php?t=491091

调用 API 可能会触发系统范围的更新,因此您无需注销/登录即可查看更改。

当然,这不限于vb.net。

Look at the stuff described in the following link:

http://www.vbforums.com/showthread.php?t=491091

Calling the API might trigger the system-wide update so you do not have to logoff/logon to see the change.

Of course, this is not limited to vb.net.

画中仙 2024-11-08 17:59:51

这是一种 PowerShell 方法:

Set-ItemProperty 'HKCU:\Control Panel\Desktop\' -Name FontSmoothing -Value "2"

您需要注销并重新登录才能生效。

注意:奇怪的是,该设置没有在“性能”中显示为启用
选项,即使它显然已打开:

在此处输入图像描述

Here's a PowerShell way to do it:

Set-ItemProperty 'HKCU:\Control Panel\Desktop\' -Name FontSmoothing -Value "2"

You'll need to log off and back on for it to take effect.

NOTE: strangely the setting doesn't show up as enabled in Performance
Options, even though it's clearly turned on:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文