'Get all supported resolutions in Node/Electron on Windows

I need to get all supported resolutions for a monitor in an electron application running on Windows. There are methods in electron to get the current screen resolution and size via the Display object. But this doesn't contain all supported resolutions.

I have tried:

  • Using a PowerShell command and parsing the output ( e.g get-wmiobject -query "select HorizontalResolution, VerticalResolution from CIM_VideoControllerResolution" | Sort-Object HorizontalResolution, VerticalResolution -descending | select HorizontalResolution, VerticalResolution) but some users have issues running Powershell on their machine (it might not be enabled, have a broken PATH, etc.). It also feels less idiomatic to use node to parse Powershell output.
  • Using an external tool like QRes.exe but this often misses some resolutions and looks a bit antiquated. Is also has issues when being executed by node, it only returns 32 bit resolutions and not any lower ones (like 16/8 bit which get reported by the CLI).
  • Parsing wmic using wmic /namespace:\\\\root\\wmi path wmimonitorlistedsupportedsourcemodes get * /format:list | findstr ActivePixels but this missed a lot of resolutions for users.

I am considering just writing a C++ addon for the node application that can get resolutions using something like EnumDisplaySettings but ideally I would like to keep this just in node if possible.

So, is it possible to get all supported screen resolutions using Node.js?
If not, what is the best way to get all supported resolutions in Node.js?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source