Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change "Windows font size (DPI)" in PowerShell?

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.

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

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.

like image 898
Laurent Finet-Baron Avatar asked Apr 28 '12 16:04

Laurent Finet-Baron


2 Answers

Apparently you can set the LogPixels property of

HKLM:/Software/Microsoft/Windows NT/CurrentVersion/FontDPI

which is reiterated in a lot of places around the net. However, I got the impression that dpi was a user setting which makes no sense to have under HKLM.

like image 161
Joey Avatar answered Nov 20 '22 15:11

Joey


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.

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
like image 9
Torben Schramme Avatar answered Nov 20 '22 14:11

Torben Schramme