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.
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
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.
Sorry, I misread the question. I thought you wanted to control the PowerShell windows.
As already mentioned you could set the LogPixels setting in the registry, to see what the current setting is, try this:
Get-Item -Path Registry::'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI' | Select-Object -ExpandProperty Property
If the LogPixels key is there it will show, you can create it if it does not exist:
Set-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI\LogPixels'
NB: You have to run this with privileges that allow you to manipulate the registry.
There is a good introduction to this over at TechNet.
@Torben Schramme I found that I had to add one more ItemProperty Win8DpiScaling for this work. But, I don't find the "logoff; exit" function working - I still have to do it manually.
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
Set-ItemProperty -Path . -Name Win8DpiScaling 0
} else {
Write-Host 'Change to 150% / 144 dpi'
Set-ItemProperty -Path . -Name LogPixels -Value 144
Set-ItemProperty -Path . -Name Win8DpiScaling 1
}
logoff;exit
After much time, I can't find anything in google.
Well, I made my own script:
$perfis = (Get-ChildItem Registry::HKEY_USERS\ | Where-Object {$_.Name -match "S-1"} | ForEach-Object {Get-ItemProperty "Registry::$_\Control Panel\Desktop" -Name "Win8DpiScaling" -ErrorAction SilentlyContinue}).PSPath
foreach ($_ in $perfis) {Set-ItemProperty -Path "Registry::$_" -Name "Win8DpiScaling" -Value 0}
$monitores = (Get-ChildItem Registry::HKEY_USERS\ | Where-Object {$_.Name -match "S-1"} | ForEach-Object {Get-ChildItem "Registry::$_\Control Panel\Desktop\PerMonitorSettings" -ErrorAction SilentlyContinue}).PSPath
foreach ($_ in $monitores) {Set-ItemProperty -Path "Registry::$_" -Name "DpiValue" -Value 0}
These simple steps worked for me:
Download Win7AndW2K8R2-KB3191566-x64.ZIP from https://docs.microsoft.com/en-us/powershell/wmf/5.1/install-configure
Unzip the file in tmp folder
Open a Powershell command window as Administrator, go in tmp folder where file has been unzipped and execute the following commands :
set-executionpolicy remotesigned
.\Install-WMF5.1.ps1