Enable/disable ClearType in Windows7

前端 未结 8 1347
栀梦
栀梦 2021-01-04 12:00

Hi 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 re

8条回答
  •  孤城傲影
    2021-01-04 12:11

    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.

提交回复
热议问题