本文介绍了获取屏幕分辨率作为cmd中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个脚本来复制特定图像,具体取决于所使用的屏幕分辨率.到目前为止,我发现wmic desktopmonitor get screenheight
给了我适当的输出,但是我在将其解析为可用变量时遇到了麻烦问题是输出在三行上,我只需要第二行的信息即可.
I need a script to copy a specific image depending on the screen resolution being used.so far I've found that wmic desktopmonitor get screenheight
is giving me the appropriate output but i'm having trouble parsing it to a useable variablethe problem is that the output is on three lines and I only need the information from the second one.
任何人都可以帮忙吗?
推荐答案
您甚至可以通过单个wmic
获取更多参数:
You can even get more parameters with one single wmic
:
for /f %%i in ('wmic desktopmonitor get screenheight^,screenwidth /value ^| find "="') do set "%%f"
echo your screen is %screenwidth% * %screenheight% pixels
如果您需要拥有自己的变量名,则要复杂一些:
If you need to have your own variablenames, it's a bit more complicated:
for /f "tokens=1,2 delims==" %%i in ('wmic desktopmonitor get screenheight^,screenwidth /value ^| find "="') do (
if "%%i"=="ScreenHeight" set height=%%j
if "%%i"=="ScreenWidth" set width=%%j
)
echo your screen is %width% * %height% pixels
如果您只需要一个值:
for /f "tokens=2 delims==" %%i in ('wmic desktopmonitor get screenheight /value ^| find "="') do set height=%%i
echo %height%
这篇关于获取屏幕分辨率作为cmd中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!