我需要一个脚本来复制特定图像,具体取决于所使用的屏幕分辨率。
到目前为止,我发现wmic desktopmonitor get screenheight
正在给我适当的输出,但我无法将其解析为可用的变量
问题是输出是三行,我只需要第二行的信息。
有人可以帮忙吗?
答案 0 :(得分:3)
@Stephan's answer已修改为与所有Windows版本(包括Windows 8)兼容:
setlocal
for /f %%i in ('wmic path Win32_VideoController get CurrentHorizontalResolution^,CurrentVerticalResolution /value ^| find "="') do set "%%i"
echo your screen is %CurrentHorizontalResolution% * %CurrentVerticalResolution% pixels
答案 1 :(得分:2)
您甚至可以使用一个wmic
获得更多参数:
for /f %%i in ('wmic desktopmonitor get screenheight^,screenwidth /value ^| find "="') do set "%%f"
echo your screen is %screenwidth% * %screenheight% pixels
如果你需要拥有自己的变量名,那就有点复杂了:
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%
答案 2 :(得分:0)
for /f "tokens=*" %%f in ('wmic desktopmonitor get screenheight /value ^| find "="') do set "%%f"
echo %size%
pause