批处理文件以更改DPI缩放因子

时间:2017-12-07 22:29:26

标签: batch-file

我正在尝试编写一个批处理文件,该文件将在首次登录时更改用户DPI设置。我已将该文件放在启动文件夹中,它将提示用户在对注册表进行任何更改之前注销。如果已经进行了更改,我不希望提示用户。这就是我到目前为止所做的:

        @echo off
REG QUERY "HKCU\Control Panel\Desktop\WindowMetrics" /v AppliedDPI  
IF %var% == 0x78 GOTO Leave
CD\
CLS
ECHO.
:LOOP
ECHO Would you like to logoff to change Scaling of windows?
ECHO.
ECHO   Y = Logoff
ECHO   N = CANCEL and return to Windows
ECHO.
SET Choice=
SET /P Choice=TYPE YOUR CHOICE AND PRESS ENTER: 
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
IF '%Choice%'=='y' GOTO LogoffNow
IF '%Choice%'=='n' GOTO Leave
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:LogoffNow
ECHO.
REG ADD "HKCU\Control Panel\Desktop" /v DpiScalingVer /t REG_DWORD /d 0x00001018 /f
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontDPI" /v LogPixels /t REG_DWORD /d 0x00000144 /f
REG ADD "HKCU\Control Panel\Desktop\WindowMetrics" /v AppliedDPI /t REG_DWORD /d 0x00000144 /f
REG ADD "HKCU\Control Panel\Desktop" /v Win8DpiScaling /t REG_DWORD /d 0x00000001 /f
REG ADD "HKCU\Control Panel\Desktop" /v LogPixels /t REG_DWORD /d 0x00000078 /f
shutdown /l
:Leave

1 个答案:

答案 0 :(得分:0)

将第2行更改为:

REG QUERY "HKCU\Control Panel\Desktop\WindowMetrics" /V AppliedDPI|FIND "0x78">NUL&&GOTO Leave

此外,如果您使用CHOICE命令, Choice /?用于,则可以将整个:LOOP部分替换为:

:LOOP
ECHO.
CHOICE /M "Would you like to logoff to change Scaling of windows"
IF ERRORLEVEL 2 GOTO Leave
:LogoffNow