更改“Windows 字体大小 (DPI)"在 PowerShell 中? [英] Change "Windows font size (DPI)" in PowerShell?

查看:62
本文介绍了更改“Windows 字体大小 (DPI)"在 PowerShell 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在办公室 (Windows 7) 上使用笔记本电脑,有工作站和双屏,在家里没有工作站.

I'm using a laptop at office (Windows 7) with a station and double screen and at home without station.

重点是每次从工作站切换到独立笔记本电脑时,我都必须更改文本大小,因为双屏上的文本大小太大,而笔记本电脑屏幕上的文本大小太小.

The point is I have to change text size each time I switch from station to standlone laptop, because the text size is too big on my double screen, but too small on my laptop screen.

继续:我右键单击桌面屏幕,选择更改分辨率,然后放大或缩小文本和其他元素"以选择 100%、125% 等...我需要重新启动会话才能应用设置.(注意:我使用的是法语系统,我想美国版本的文本并不完全相同).

To proceed: I right-click on desk screen, choose change resolution then "get text and other elements bigger or smaller" to choose 100%, 125%, etc... I need to restart my session to get the settings applied. (Note: I'm using a French system, and texts are not exactly the same on us version I suppose).

这不是很方便,所以我想自动执行此操作,也许使用 PowerShell 脚本.

It's not very convenient so I'd like to automate this, perhaps with a PowerShell script.

理想情况下,脚本可以检测我是单独使用笔记本电脑还是使用带有两个屏幕的工作站).另外,无需重新启动会话(我怀疑最后一点是否可行).

Ideally the script may detect if I'm using laptop alone or station with its two screens). Plus, without session restart (I doubt this last point is feasible).

我该如何开始?如果可以的话.

How do I get started? If this is possible.

推荐答案

正如在其他答案中所假设的,HKLM 下的设置不是正确的位置,因为 dpi 缩放是用户定义的设置.正确的注册表项是 HKCU:Control PanelDesktop,值为 LogPixels.

As supposed in the other answers, the setting under HKLM is not the correct place as the dpi scaling is a user defined setting. The correct registry key is HKCU:Control PanelDesktop with the value LogPixels.

有关所有 DPI 相关注册表设置的更多信息可以在 与 DPI 相关的 API 和注册表设置.

More information about all DPI-related registry settings can be found in DPI-related APIs and registry settings.

我编写了一个很小的 ​​PowerShell 脚本,它根据当前的缩放比例更改 DPI 缩放比例并执行用户注销,因此当我将设备放在不同的显示器上时,我只需要执行该脚本.

I wrote a tiny PowerShell script that changes the DPI scaling depending on the current scaling and performs the user logoff, so I just have to execute the script when I put my device to a different monitor.

cd 'HKCU:Control PanelDesktop'
$val = Get-ItemProperty -Path . -Name "LogPixels"
if($val.LogPixels -ne 96)
{
    Write-Host 'Change to 100% / 96 dpi'
    Set-ItemProperty -Path . -Name LogPixels -Value 96
} else {
    Write-Host 'Change to 150% / 144 dpi'
    Set-ItemProperty -Path . -Name LogPixels -Value 144
}

logoff;exit

这篇关于更改“Windows 字体大小 (DPI)"在 PowerShell 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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