|
本帖最后由 xmzhqw 于 2024-5-14 10:48 编辑
Smine 大:
您的PE中的PECMD好像都是用比较旧的版本,最新版的用了以后好像都会提示一个错误,包括昨天刚出的PECMD版本也会。只是最近想要增加一个调整屏幕DPI的右键无法添加,提示版本太低。
近几天,mdyblog大好像都在更新PECMD,能不能向他反馈一下您的问题?让他一并解决了您的PE中发现的问题?能升级到更新的版本不是更好?mdyblog 大的帖子 [更新376#2825]PECMD2012.1.80.13_Win32_64.多窗口多线程.裸机系统2.3.3.1+18M酷M...
我这个屏幕DPI工具印象中是来自5大的,但一下子找不到了,代码如下:(无法传附件,只好把代码复制了)
- #code=950T936
- //by Jet Chan,2022/5/30 modify by hhh333
- set^ EnviMode=1
- set^ ForceLocal=1
- set ?ver=WinVer
- ifex $%ver%<0x600000000, exit //nt5
- //用到了变量偏移,新版PECMD才支持:%ProgramFiles:~6,1% 或 %^ProgramFiles:~6;1% 或 %^ProgramFiles:~6:1%
- team mstr * Build=<-1>pecmdbuild| sed -ex Build=0,[^0-9],,Build
- ifex $[ %pecmdver%<201201880588 | %Build%<20220527 ], team mess=+icon6 PECMD 版本低于 201201.88.05.88 Build: 2022-05-27 @错误(设置dpi)#ok*5000| exit
- set RegKey=HKLM\SOFTWARE\Classes\DesktopBackground\Shell\SetDPI
- set MainIcon=%%%%SystemRoot%%%%\System32\shell32.dll,-270 //display.dll,-1
- set SubIcon==%%%%SystemRoot%%%%\System32\shell32.dll,-44
- set Flags= (当前值)
- set RecommendIndex= //推荐值
- set RelativeIndex= //相对值,即100%所对应的值
- set MessCount=0
- set DoSilence=
- set DelKey=!
- set RegNum=
- set DoReg=
- set Auto=
- set dpi=
- find $%~1<>,
- {*
- set k0=1
- loop #%k0%<%#,
- {*
- mstr -rq++ k1=<%k0%>%*
- find $%k1:~;4%=/reg, team set DoReg=%k1%| calc #k0=%k0%+1| exit -
- find $%k1%=/s, team set DoSilence=%k1%| calc #k0=%k0%+1| exit -
- find $%k1%=/auto, team set Auto=%k1%| calc #k0=%k0%+1| exit -
- team calc #dpi=%k1%| ifex $%dpi%<100, set dpi=| calc #k0=%k0%+1
- }
- }
- find *<>Auto, set dpi=
- call GetDpiPercent
- find *<>DoReg, call RegDpiMenu "%DoReg:~4%"
- find [ *<>DoReg & *=dpi & *=Auto ], exit
- ifex $%ver%>=0xA00003839, //低于win10.0.14393不支持SystemParametersInfoW函数
- {*
- call GetRelativeIndex RelativeIndex
- ifex $%error%<>0,!! team find *=DoSilence, mess=+icon6 函数错误,程序即将退出! @错误(设置dpi)#OK*3000| exit
- }
- call SetAutoDpi
- call CheckDpiRange dpi
- ifex $%percent%=%dpi%, exit
- //计算最大dpi公式(非自定义,自定义最大dpi为500%) //http://bbs.c3.wuyou.net/forum.php?mod=redirect&goto=findpost&ptid=430063&pid=4576157
- //暂不采用微软官方公式: //calc MaxDpi=int(%DeskTopVertRes%/720*100) //https://docs.microsoft.com/zh-cn/windows-hardware/manufacture/desktop/dpi-related-apis-and-registry-settings?view=windows-11
- calc MaxDpi=int(%DeskTopVertRes%/600*100)
- set MaxDpiOld=%MaxDpi%
- call CheckDpiRange MaxDpi
- find *=DoSilence,
- {*
- find *<>RelativeIndex,
- {*
- ifex $[ %dpi%>%MaxDpi% & '%^UserName%'<>'SYSTEM' ],!! team call IfOrNotShutDown| ^ifex $%%error%%<>0, exit
- }!
- {*
- find $%^UserName%<>SYSTEM,!! team call IfOrNotShutDown| ^ifex $%%error%%<>0, exit
- }
- }
- call ChangeDpiInApi %dpi%
- //新进程才能得到更改后的dpi
- exec*- -err+ -incmd CurDpi=pecmd load "%CurFile%*GetDpiPercent" --console
- ifex $%CurDpi%<>%dpi%,
- {
- //SYSTEM用户注销失败(shutdown.exe /l 也失败)
- find $%^UserName%<>SYSTEM,
- {
- //能注销
- ifex $%MessCount%=0,
- {
- //前面未询问过是否注销
- call IfOrNotShutDown
- ifex $%error%=0,
- {
- //注销
- call ChangeDpiInReg
- call SetRightMenu
- shut L
- }!
- {
- //不注销,还原dpi
- call ChangeDpiInApi %percent%
- }
- }!
- {
- //前面已询问过是否注销
- call ChangeDpiInReg
- call SetRightMenu
- shut L
- }
- }!
- {
- //不能注销
- ifex $%dpi%<=%MaxDpi%, set FinalDpi=%CurDpi%! set FinalDpi=%MaxDpi%
- find *=DoSilence, mess=+icon1 无法将 dpi 更改为 %dpi%%,最大仅支持 %FinalDpi%% @提示(设置dpi)#OK*5000
- }
- }!
- {
- call ChangeDpiInReg
- call SetRightMenu
- }
- exit
- _sub GetDpiPercent *
- call $--ret:ret user32.dll,SetProcessDPIAware //成功:ret=1
- set hdcCount=0
- loop #%hdcCount%<50,
- {*
- call $--ret:hdc user32.dll,GetDC,#0
- calc #hdcCount=%hdcCount%+1
- ifex $%hdc%>0, exit
- wait 0.9
- }
- call $--ret:LogPixels Gdi32.dll,GetDeviceCaps,#%hdc%,#90 //dpi高 //#88为宽
- call $--ret:DeskTopVertRes Gdi32.dll,GetDeviceCaps,#%hdc%,#117 //分辨率高 //#118为宽
- calc percent=%LogPixels%/96*100
- find $%~1=--console,!! writ *fv --,,percent
- _end
- _sub SetRightMenu
- set v0=%RegKey%\shell
- regi --init --ak $%v0%\,v1
- forx *nl v1,v2,
- {
- regi --init $%v0%\%v2%\command\\,v3
- mstr * v4=<-1>v3
- find $%^UserName%=SYSTEM, set v5=%CurDpi%! set v5=%dpi%
- ifex $%v4%=%v5%, set v6=%v4%%%%Flags%! set v6=%v4%%%
- ifex $%v4%=%dpi%, set v7=%SubIcon%! set v7=%DelKey%
- ifex $%v4%>=100, regi $%v0%\%v2%\\MUIVerb=%v6%
- regi $%v0%\%v2%\\Icon%v7%
- }
- _end
- _sub CheckDpiRange
- set r0=
- ^ifex $%%%~1%%>250, set r1=50! set r1=25
- ^calc r2=int(%%%~1%%/%%r1%%)*%%r1%%
- ifex $%r2%<100, set r2=100
- ifex $%r2%>500, set r2=500
- set-ret %~1=%r2%
- _end
- _sub GetRelativeIndex
- set$# j0=*4 0
- call $--bool --qd --ret:ret user32.dll,SystemParametersInfoW,#158,0,*j0,1
- //call $--ret:ret Kernel32.dll,GetLastError //官方说GetLastError返回0则失败,但事实不管成功失败,全是0
- //ifex $%ret%<=0, exit //排除不支持的系统。
- set?ints j0=j1 //j1对应100% //http://bbs.wuyou.net/forum.php?mod=redirect&goto=findpost&ptid=430063&pid=4553783
- ifex $%j1%>0, team exit= 1| exit
- set-ret %~1=%j1%
- exit= 0
- _end
- _sub IfOrNotShutDown
- find *<>DoSilence, team exit= 0| exit
- set-ret MessCount=1
- mess=+icon1 将 dpi 更改为 %dpi%%,需要注销才能生效,是否继续? @提示(设置dpi)#YN*5000$N
- find $%yesno%=no, exit= 1! exit= 0
- _end
- _sub SetAutoDpi *
- find *=dpi,
- {*
- find *<>RelativeIndex,
- {*
- //https://www.codenong.com/35233182/
- set RecommendIndex=0 //0为系统推荐值,系统自动算的,可能是100%,也可能是350%
- calc i0=(%RecommendIndex%-%RelativeIndex%)-6 //计算250%以上的步进数(步进单位为50%)
- ifex $%i0%>0, calc dpi=int(6*25+%i0%*50+100)! calc dpi=int[(%RecommendIndex%-%RelativeIndex%)*25+100]
- }!
- {*
- //推荐dpi计算公式:最大dpi/1.5
- calc dpi=int(%MaxDpiOld%/1.5)
- call CheckDpiRange dpi
- }
- }
- _end
- _sub ChangeDpiInReg
- //用改注册表+注销方式实现自动 dpi 缩放,不需要SystemParametersInfoW函数,支持所有windows系统
- calc h0=int(%dpi%/100*96)
- regi #HKCU\Control Panel\Desktop\\LogPixels=%h0%
- regi #HKCU\Control Panel\Desktop\WindowMetrics\\AppliedDPI=%h0%
- ifex $%ver%>=0x600020000,!! regi #HKCU\Control Panel\Desktop\\Win8DpiScaling=1
- _end
- _sub ChangeDpiInApi
- //SystemParametersInfoW函数有局限性,dpi 大于显示器 ppi 时将被重置为 ppi 最大值
- //https://www.sysceo.com/forum/thread-44479-1-1.html
- ifex [ *<>RelativeIndex & $%~1<=%MaxDpi% ],
- {
- find *=RecommendIndex,
- {*
- ifex $%~1>250,
- {*
- ^calc RecommendIndex=int[(%~1-250)/50+(250-100)/25+%RelativeIndex%]
- }!
- {*
- ^calc RecommendIndex=int[(%~1-100)/25+%RelativeIndex%]
- }
- }
- call $--qd# user32.dll,SystemParametersInfoW,159,%RecommendIndex%,0,1
- envi @@DeskTopFresh=1
- exec -incmd pecmd envi @@DeskTopFresh=clearicon;1 //刷新桌面图标缓存
- }
- _end
- _sub RegDpiMenu
- set p1=regi $%RegKey%
- %p1%\\%DelKey%
- set p=%~1
- ifex [ *=p | $%p%>13 ], set p=13 //默认13个右键(500%),理论上支持无穷个,但系统限制只能到500%
- calc #p=%p%
- ifex $%p%>0,
- {
- sed -ex p11=1:0,\$,#,p1
- |%p1%\\SubCommands=|
- %p1%\\MUIVerb=屏幕 dpi 缩放比例(&Z)
- %p1%\\Position=Bottom
- %p1%\\Icon=%MainIcon%
- %p11%\\SeparatorBefore=1 //分隔线
- %p11%\\SeparatorAfter=1 //分隔线
- calc #p=%p%-1
- set p2=-1
- set p3=1
- loop #%p2%<%p%,
- {*
- ifex $%p3%<2, calc p4=%p2%*25+100
- ifex $%p4%>250,
- {*
- calc p4=250+%p3%*50
- calc p3=%p3%+1
- }
- ifex $%p4%=%percent%,
- {*
- set CurFlags=%Flags%
- set Icon=%SubIcon%
- }!
- {*
- set CurFlags=
- set Icon=%DelKey%
- }
- ifex $%p4%<100, set p5=自动! set p5=%p4%%%
- calc p6=%p2%+1
- //以下代码为自创9进制,即是将10转换成91,11转换成92,20转换成992,以此类推(写注册表时10、100、1000等会排到9前面,比较蛋疼)
- ifex $%p6%>=9,
- {*
- calc #p7=%p6%/9
- calc p8=%p6%%9
- code *,9,*ansi,p9
- set= pa=*%p7% %p9%
- code ***ansi,pa,**uni,pb
- set p6=%pb%%p8%
- }
- |%p1%\shell\%p6%\\=|
- %p1%\shell\%p6%\\MUIVerb=%p5%%CurFlags%
- %p1%\shell\%p6%\command\\="%MyName%" load "%CurFile%" %p4%
- %p1%\shell\%p6%\\Icon%Icon%
- calc p2=%p2%+1
- }
- }
- _end
复制代码
|
|