找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 34078|回复: 6

[系统相关] 如何通过批处理获取显示器当前的分辨率呢?

[复制链接]
发表于 2009-4-13 16:26:55 | 显示全部楼层 |阅读模式
本帖最后由 pcl_test 于 2016-6-15 11:30 编辑

大家好!请教一下大家如何通过bat获取显示器当前的分辨率呢?
发表于 2009-4-13 16:48:08 | 显示全部楼层
  1. wmic desktopmonitor get ScreenWidth,ScreenHeight
复制代码
发表于 2009-4-13 18:36:03 | 显示全部楼层
  1. @echo off
  2. for /f "tokens=1,3 eol=H skip=8" %%a in ('reg query hkcc\system\currentcontrolset\control\video /s') do (
  3.   if /i "%%a"=="DefaultSettings.XResolution" (set /a X=%%b) else (
  4.     if /i "%%a"=="DefaultSettings.YResolution" set /a Y=%%b
  5.   )
  6. )
  7. echo %x%*%y%
  8. pause
复制代码
发表于 2009-4-13 23:08:19 | 显示全部楼层
  1. mshta vbscript:prompt("",screen.Width^&" "^&screen.Height)(close)
复制代码
  1. mshta "javascript:prompt('',screen.Width+' '+screen.Height);close();"
复制代码

[ 本帖最后由 zqz0012005 于 2009-4-13 23:12 编辑 ]
发表于 2016-6-16 14:55:47 | 显示全部楼层
vbs
  1. '一
  2. Set html=CreateObject("HtmlFile")
  3. Set screen=html.ParentWindow.Screen
  4. Msgbox screen.width &" "& screen.height

  5. '二
  6. Set wmi = GetObject("winmgmts:\\.\root\cimv2")
  7. Set Items = wmi.ExecQuery("Select * from Win32_DesktopMonitor")
  8. For Each Item in Items
  9.     If Item.ScreenHeight <>"" and Item.ScreenWidth <>"" Then
  10.         Msgbox  Item.ScreenWidth&" "& Item.ScreenHeight
  11.     End If
  12. Next

  13. '三
  14. Set ie = CreateObject("InternetExplorer.Application")
  15. ie.Navigate "about:blank"
  16. Set screen=ie.Document.parentWindow.screen
  17. Msgbox screen.width &" "& screen.height
复制代码
发表于 2025-10-2 23:03:24 | 显示全部楼层
  1. @echo off
  2. mshta vbscript:CreateObject^(^"Wscript.Shell^"^).Run(^"cmd /c^"^&^"echo ^"^&CreateObject^(^"HtmlFile^"^).ParentWindow.Screen.width^&^"^>%temp%\ScreenW.txt^")(window.close)
  3. mshta vbscript:CreateObject^(^"Wscript.Shell^"^).Run(^"cmd /c^"^&^"echo ^"^&CreateObject^(^"HtmlFile^"^).ParentWindow.Screen.height^&^"^>%temp%\ScreenH.txt^")(window.close)
  4. set /p "Width=" 0<%temp%\ScreenW.txt
  5. set /p "Height=" 0<%temp%\ScreenH.txt
  6. del /f /q %temp%\ScreenW.txt
  7. del /f /q %temp%\ScreenH.txt
  8. echo %Width% %Height%
  9. pause
复制代码
发表于 2025-10-7 13:13:06 | 显示全部楼层
本帖最后由 aloha20200628 于 2025-10-7 13:46 编辑


批处通过mshta脚本调用网页属性值可直接获取当前屏幕分辨率,但仅为取值则会突显其产生屏闪的缺陷。因此可选用 wmic 和 powershell 方法,但前者采用 desktopmonitor 通道获取可能会有系统兼容性问题,采用 Win32_VideoController 通道获取比较稳妥;powershell 方法就是首启速度略慢,以下是三段批处示例代码...

一。mshta 版本

  1. @echo off & for /f "tokens=1-2 delims=," %%a in ('mshta "javascript:new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(screen.width+','+screen.height);close();" ') do (set/a "w=%%a,h=%%b")
  2. echo,w=%w%,h=%h%&pause&exit/b
复制代码
二。wmic 版本

  1. @echo off &for /f "tokens=1-2 delims= " %%a in (
  2.     'wmic path Win32_VideoController get CurrentHorizontalResolution^,CurrentVerticalResolution'
  3. ) do (set/a "w=%%a,h=%%b" 2>nul)
  4. echo,w=%w%,h=%h%&pause&exit/b
复制代码
三。powershell 版本

  1. @echo off &for /f "tokens=1-2 delims=," %%a in (
  2.     'powershell "$g=Get-WmiObject win32_videocontroller;''+$g.CurrentHorizontalResolution+','+$g.CurrentVerticalResolution" ') do (set/a "w=%%a,h=%%b")
  3. echo,w=%w%,h=%h%&pause&exit/b
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 07:05 , Processed in 0.019548 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表