How to get the current screen resolution on windows via command line?

I'm trying get the current screen resolution on windows via command line.
Based on most of the answers I've found, I should use:

wmic desktopmonitor get screenheight, screenweight

But this returns the max supported resolution of the display device, not the current one, which is what I need.

Example:
I'm using a 4k monitor, but currently set to display only at 1920x1080. When I run the command above, I get:

ScreenHeight ScreenWidth
2160 3840

enter image description here

How do I get the current screen resolution on windows via command line?

4

2 Answers

Dealing with high DPI made this somewhat challenging because most Windows API functions return a scaled version of the resolution for compatibility unless the application declares high DPI awareness. Inspired by this Stack Overflow answer I wrote this PowerShell script:

Add-Type @"
using System;
using System.Runtime.InteropServices;
public class PInvoke { [DllImport("user32.dll")] public static extern IntPtr GetDC(IntPtr hwnd); [DllImport("gdi32.dll")] public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
}
"@
$hdc = [PInvoke]::GetDC([IntPtr]::Zero)
[PInvoke]::GetDeviceCaps($hdc, 118) # width
[PInvoke]::GetDeviceCaps($hdc, 117) # height

It outputs two lines: first the horizontal resolution, then the vertical resolution.

To run it, save it to a file (e.g. screenres.ps1) and launch it with PowerShell:

powershell -ExecutionPolicy Bypass .\screenres.ps1
1

I had a similar problem.
Try this:

wmic PATH Win32_VideoController GET CurrentVerticalResolution,CurrentHorizontalResolution

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like