icePain12
icePain12

Reputation: 1

How can I modify custom scaling using PowerShell?

Thanks for your attention.

to put you in context, I have a P.C with 2 different monitors and i want to easly change display config from one to another, and as it is so tedious to change manually the configuration every time I change my monitor, I'm trying to create a PowerShell file .ps1 that help me to change display configuration easily. I found that there is a module called DisplaySettings that can help me to set up the Display Resolution using Set-DisplayResolution -Width 1920 -Height 1080 https://www.powershellgallery.com/packages/DisplaySettings/0.0.2 so I solved the first thing, The next thing I want to achieve is to effortlessly change the (System > Display > Custom Scaling) value that it is a value between 100 - 500 to set the scale that Windows Show elements. but I can't find a way of doing it. Can someone give an Idea? I'm using Windows 11 Pro, and PowerShell 7.5.0 if this information is required.

I tried to ask chatGPT but what it told me was:

There is no native cmdlet that directly modifies the "Custom Scaling" option (which accepts a value between 100 and 500) in Windows via PowerShell. However, you can achieve this by modifying the registry values that Windows uses to determine the DPI scaling factor.

Generally, Windows uses the LogPixels registry key (located at HKCU:\Control Panel\Desktop) to determine the user’s DPI. In this system, the default value is 96 (which corresponds to 100% scaling). To calculate the corresponding value for a desired percentage, you can use the following formula:

Value for LogPixels = 96 × (Desired Percentage / 100)

For example:

Additionally, you need to ensure that Windows uses the LogPixels value for scaling. To do that, set the Win8DpiScaling registry key to 1.

Here’s an example of how to do this in PowerShell:

# Enable the use of custom scaling
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "Win8DpiScaling" -Value 1

# Calculate the LogPixels value based on the desired percentage.
# For example, for 150% scaling:
$percentage = 150
$logPixels = [int](96 * ($percentage / 100))

# Set the LogPixels value
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "LogPixels" -Value $logPixels -Type DWord

Important:

With this method, you are essentially "simulating" the change of the Custom Scaling option, since Windows uses these values to determine the interface scaling.

but I'm not sure if I can trust on it.

Upvotes: 0

Views: 33

Answers (0)

Related Questions