我需要通过cmd
(或任何VBS/JS等脚本)或从注册表中启用/禁用 ClearType(或“调整 Windows 外观和性能 > 平滑屏幕字体边缘”),而无需注销或重新启动 Windows。
也许可以仅为一个应用程序启用 ClearType。
我需要通过cmd
(或任何VBS/JS等脚本)或从注册表中启用/禁用 ClearType(或“调整 Windows 外观和性能 > 平滑屏幕字体边缘”),而无需注销或重新启动 Windows。
也许可以仅为一个应用程序启用 ClearType。
在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
表示启用。无需重新启动。
为了提供更多的选项,我有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);
}
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)
制作扩展名为.reg
的文件,这是文件注册表。
禁用屏幕字体的平滑边缘。
[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="0"
启用屏幕字体的平滑边缘
[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="2"
您也可以通过命令行完成此操作。以下是命令的语法:
REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d Data] [/f]
您必须注销才能使您所做的更改生效
我不确定如何在不重新启动的情况下完成它...
但我发现仅更改FontSmoothing键是不够的...
要完全删除ClearType和FontSmoothing,请查看以下完整过程:
请查看以下链接中描述的内容:
http://www.vbforums.com/showthread.php?t=491091
调用API可能会触发系统范围的更新,因此您无需注销/登录即可查看更改。
当然,这不仅限于vb.net。
.ps1
文件。然后你可以在命令行中运行它,例如powershell "& 'C:\myscript.ps1' 1"
。不过也有可能调整系统注册表,这样你就可以双击该文件来运行它。 - skinkSet-ExecutionPolicy Unrestricted -Force
应该允许运行所有脚本,但是Set-ExecutionPolicy RemoteSigned
可能更安全。请参阅:https://dev59.com/kG855IYBdhLWcg3w_5qm - skinkpowershell "& 'C:\myscript.ps1' 0"
。 - user1306322