Jump to content











Photo
- - - - -

WinPE Screen Resolution and DPI scaling on UEFI firmware


  • Please log in to reply
No replies to this topic

#1 misty

misty

    Gold Member

  • Developer
  • 1069 posts
  •  
    United Kingdom

Posted 16 March 2023 - 12:56 PM

This topic is based on observations on screen resolution and DPI scaling in WinPE. The test system including a Lenovo Thinkpad T470s with FHD resolution, with some tests also completed in VMWare Workstation Player. This system has UEFI firmware with CSM disabled. WinPE was based on boot.wim from Windows 21H2 installation media - modified using the Mini-WinFE project. A more detailed guide with screenshots is available - http://mistyprojects...npe_dpi/dpi.htm


Screen resolution can be changed from a running WinPE booted on BIOS firmware. Changing the screen resolution on UEFI firmware is not so simple. Settings in unattend.xml appear to be ignored and the screen resolution is fixed. Based on available information screen resolution appears to be set based on Graphics Output Protocal (GOP) mode. Once WinPE is booted, the resolution cannot be changed.


Investigating further, the screen resolution in WinPE is set to the resolution defined/set by the Windows Boot Manager. bcdedit.exe can be used to modify the BCD store and set the menu resolution that will subsequently by used in WinPE, however the graphicsresolution element does not support many options. Examples of resolutions that can be set using graphicsresolution include -
bcdedit.exe /set {globalsettings} graphicsresolution 800x600
bcdedit.exe /set {globalsettings} graphicsresolution 1024x600
bcdedit.exe /set {globalsettings} graphicsresolution 1024x768
Attempting to use an unsupported resolution (unsupported by bcdedit - not the hardware) resulted in the following output -
C:\windows\system32>bcdedit.exe /set {globalsettings} graphicsresolution 1920x1080
The integer data is not valid as specified.
Run "bcdedit /?" for command line assistance.
The parameter is incorrect.
The highestmode option is also supported in bcdedit.exe. This option will enable boot applications to use the highest graphical mode detected by the firmware -
bcdedit.exe /set {globalsettings} highestmode on
Exercise caution when using higestmode, as depending on the scale used on WinPE (see below) WinPE may be unusable on high resolution displays. As an example, running WinPE with 100% scaling on a Surface Pro with a screen size of 12.3" and maximum resolution of 2736 x 1824 was unreadable due to the content being hard to see and UI targets being difficult to select.


The GRUB4EFI boot manager (aka Grub4dos-for_UEFI) can be used to set a wider range of screen resolutions before control is passed to the Windows Boot Manager. Setting the screen resolution in a GRUB4EFI menu or at the commandline and then chainloading the Windows Boot Manager should keep the resolution set in GRUB4EFI. NOTE that this may not work if the screen resolution is configured in the BCD store (e.g. graphicsresolution or highestmode is set) as these settings will override GRUB4EFI.


To find supported resolutions, use the graphicsmode --info command on the GRUB4EFI commandline. On the test system, the following resolutions are supported -
MODE  Format   Resolution      BitPixel
260     1      1280 x 1024       32
259     1      1024 x 768        32
258     1      800 x 600         32
257     1      640 x 480         32
256     1      1920 x 1080       32
WinPE does not support resolutions lower than 768 vertical lines. This limits supported resolutions on the T470s test system to the following -
1024 x 768 
1280 x 1024
1920 x 1080
GRUB4EFI configuration file (menu.lst) menu entries. Each entry uses the graphicsmode command to set a supported screen resolution prior to chainloading the Windows boot manager (/efi/microsoft/boot/bootmgfw.efi) -
color white/black black/white light-blue/black light-red/black
default 4

title Windows 1024x768
find --set-root /efi/microsoft/boot/bootmgfw.efi
graphicsmode -1 1024 768
chainloader /efi/microsoft/boot/bootmgfw.efi

title Windows 1280x1024
find --set-root /efi/microsoft/boot/bootmgfw.efi
graphicsmode -1 1280 1024
chainloader /efi/microsoft/boot/bootmgfw.efi

title Windows 1920x1080
find --set-root /efi/microsoft/boot/bootmgfw.efi
graphicsmode -1 1920 1080
chainloader /efi/microsoft/boot/bootmgfw.efi

title commandline
commandline

title reboot
reboot

cheers.gif

misty
  • Tokener and stayboogy like this

#2 misty

misty

    Gold Member

  • Developer
  • 1069 posts
  •  
    United Kingdom

Posted 16 March 2023 - 12:57 PM

The previous post covered setting the screen resolution. This section covers changing the DPI scale used in WinPE. By default WinPE versions 4/5.x/10.x/11.x will automatically set a scaling level based on a combination of the physical panel size and screen resolution. The ThinkPad T470s test system has a physical panel size of 14". Running in FHD on this display panel, WinPE and Windows set a scaling level of 150%


The information in this section has been adapted from an article by Michael Albert - Windows PE: Disable DPI autoscaling. Based on the information provided by Michael, adding three registry settings will disable auto scaling and will set a fixed custom scaling level. The following registry settings need to be applied to an offline WinPE image (with keyname edited to refect the mount point used for the offline registry hive) -
reg add "HKCU\Control Panel\Desktop" /t REG_DWORD /v LogPixels /d 96 /f
reg add "HKCU\Control Panel\Desktop" /v Win8DpiScaling /t REG_DWORD /d 0x00000001 /f
reg add "HKCU\Control Panel\Desktop" /v DpiScalingVer /t REG_DWORD /d 0x00001018 /f
The LogPixels value is used to set the custom scaling, with scaling between 100%-500% supported. Value starts at 96 with incremental steps of 24 adding a further 25% scaling.

LogPixels value of 96 = 100%
LogPixels value of 120 = 125%
LogPixels value of 144 = 150%
LogPixels value of 168 = 175%
LogPixels value of 192 = 200%
etc


Using wimlib to show an example, with following paths/settings -
- d:\boot.wim = path to .wim file containing WinPE
- 2 = index/image number (in d:\boot.wim) containing WinPE
- D:\wimlib\temp = Work directory - the WinPE default registry hive will be extracted here.
- D:\wimlib\wimlib-imagex.exe = Path to wimlib-imagex.exe.


Extract the default registry hive from image 2 in d:\boot.wim to the D:\wimlib\temp directory -
D:\wimlib\wimlib-imagex.exe extract D:\boot.wim 2 /Windows/System32/config/default --dest-dir=D:\wimlib\temp

Use reg.exe to mount the extracted default hive (as HKLM\_WinPE_Default) -
reg.exe load HKLM\_WinPE_Default D:\wimlib\temp\default

Apply the registry settings, editing the LogPixels value as required. In the example below a LogPixels value of 96 is set (100% scale) -
reg add "HKLM\_WinPE_Default\Control Panel\Desktop" /v LogPixels /t REG_DWORD /d 96 /f
reg add "HKLM\_WinPE_Default\Control Panel\Desktop" /v Win8DpiScaling /t REG_DWORD /d 0x00000001 /f
reg add "HKLM\_WinPE_Default\Control Panel\Desktop" /v DpiScalingVer /t REG_DWORD /d 0x00001018 /f

Unload the default registry hive -
reg.exe unload HKLM\_WinPE_Default

Inject the updated default registry hive back to boot.wim -
D:\wimlib\wimlib-imagex.exe  update D:\boot.wim 2 --command="add 'D:\wimlib\temp\default' '/Windows/System32/config/default'"
:cheers:

Misty
  • Tokener likes this

#3 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 17 March 2023 - 09:58 AM

Very interesting.

 

This is what the good MS guys (and all the other peeps that brought us UEFI) like to call "simplifying" (as opposed to the bad, bad, BIOS).

 

Good work, thanks.  :thumbsup:

 

 

Small glitch: your last code needs to be corrected ( it is a repetition of the "Unload the default registry hive -" instead of the "Inject the updated default registry hive back to boot.wim -")

 

:duff:

Wonko


  • Tokener and misty like this

#4 misty

misty

    Gold Member

  • Developer
  • 1069 posts
  •  
    United Kingdom

Posted 17 March 2023 - 06:04 PM

@Wonko
Thanks for the feedback - and good spot regarding the missing/incorrect code in the "Inject the updated default registry hive back to boot.wim" section of post #2. Post #2 edited and corrected.
  • Tokener likes this

#5 stayboogy

stayboogy

    Member

  • Members
  • 49 posts
  •  
    United States

Posted 27 November 2023 - 08:49 PM

You rock, Misty. I really needed this.



#6 misty

misty

    Gold Member

  • Developer
  • 1069 posts
  •  
    United Kingdom

Posted A week ago

SetDPI by imniko can be used to set / change / check DPI scaling from WinPE running on UEFI firmware. The program has been compiled as a 64-bit executable and is available from github - https://github.com/imniko/SetDPI

This is a commandline tool. Use the following syntax to check the current setting/scale (output is DPI as a percentage) -
setdpi.exe get
Or
setdpi.exe value
To change resolution on the main monitor use the following syntax (where scale is a percentage) -
setdpi.exe scale
E.g. To set scale as 125% use the following -
setdpi.exe 125
I tried setting a scale of 200% on the laptop I am using to write this post - scale was set as 175 and I believe this is the maximum supported by my panel?

There are file dependencies that will need to be added to your WinPE -
- msvcp140.dll
- vcruntime140.dll
- vcruntime140_1.dll

The file dependencies can be added to your \Windows\System32\ directory or alternatively added to the path from which setDPI.exe is running.

When using SetDPI my menu system resolution/scale and running windows were unchanged. After closing dowm and restarting my applications they ran at the new scale - as this is a WinPE the shell cannot be shut down and restarted as it will end the session.

____________________

windows-DPI-scaling-sample is another 64-bit program that can be used to set/check DPI scale in WinPE running on UEFI firmware.

This is another github project, however is a GUI tool - the author is lihas. It is available from the following url - https://github.com/l...-scaling-sample

It has the following file dependency that will need to be added to your WinPE -
- oledlg.dll

As per SetDPI, the file dependencies can be added to your \Windows\System32\ directory or alternatively added to the path from which DPIScalingMFCApp.exe is running.

When using DPIScalingMFCApp.exe my menu system resolution/scale and running windows were unchanged. After closing dowm and restarting my applications they ran at the new scale - as this is a WinPE the shell cannot be shut down and restarted as it will end the session.

cheers.gif

misty




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users