更改"Windows字体大小(DPI)".在PowerShell中? [英] Change "Windows font size (DPI)" in 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缩放比例是用户定义的设置.正确的注册表项是值为LogPixels
的HKCU:\Control Panel\Desktop
.
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 Panel\Desktop
with the value LogPixels
.
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 Panel\Desktop'
$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屋!