You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过CMD、PowerShell(无需权限)或Python获取Windows各显示器的分辨率、色深及缩放比例?

获取Windows显示器信息的可行方法

一、PowerShell(无需管理员权限)

你提到的System.Windows.Forms方法受限于受限语言模式,需要管理员权限才能绕过,试试这些无需管理员的替代方案:

1. 获取分辨率与色深

用CIM实例直接读取系统硬件信息,完全不受权限限制:

Get-CimInstance Win32_VideoController | 
    Select-Object Name, 
                  @{Name='宽度(像素)'; Expression={$_.CurrentHorizontalResolution}},
                  @{Name='高度(像素)'; Expression={$_.CurrentVerticalResolution}},
                  @{Name='色深(位)'; Expression={$_.BitsPerPixel}}

2. 获取缩放比例

通过读取系统注册表的显示器配置项,提取DPI计算缩放比例:

Get-ChildItem "HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" | 
    ForEach-Object {
        $configPath = Join-Path $_.PSPath "00\00"
        if (Test-Path $configPath) {
            $dpiData = Get-ItemProperty -Path $configPath -Name DpiValue -ErrorAction SilentlyContinue
            $resData = Get-ItemProperty -Path $configPath -Name PrimitiveOutputSize -ErrorAction SilentlyContinue
            if ($dpiData -and $resData) {
                [PSCustomObject]@{
                    显示器标识 = $_.PSChildName
                    缩放比例(%) = ($dpiData.DpiValue / 96) * 100
                    实际宽度(像素) = $resData.PrimitiveOutputSize.Width
                    实际高度(像素) = $resData.PrimitiveOutputSize.Height
                }
            }
        }
    }

二、命令提示符(CMD)

用wmic快速获取基础的分辨率和色深:

wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution,BitsPerPixel,Name

要获取缩放比例,可通过注册表查询手动计算(DpiValue除以96再乘100就是百分比):

reg query "HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration" /s /v DpiValue

三、Python(无需管理员权限)

两种方案可选,都能拿到所有需要的信息:

1. 用screeninfo库(简单易上手)

先安装依赖:

pip install screeninfo

然后运行代码:

from screeninfo import get_monitors

for monitor in get_monitors():
    print(f"显示器名称: {monitor.name}")
    print(f"分辨率: {monitor.width}×{monitor.height}")
    print(f"缩放比例: {monitor.scale * 100}%\n")

2. 用pywin32获取完整信息(含色深)

先安装pywin32:

pip install pywin32

然后执行以下代码,直接输出所有显示器的宽高、色深和缩放比例:

import win32api
import win32con
import win32gui

def get_all_monitor_info():
    monitors = []
    def enum_monitors_callback(hMonitor, _, __, ___):
        monitor_info = win32gui.GetMonitorInfo(hMonitor)
        # 获取DPI缩放比例
        dpi_x = win32api.GetDpiForMonitor(hMonitor, win32con.MDT_EFFECTIVE_DPI)[0]
        scale_percent = round((dpi_x / 96) * 100)
        # 获取色深
        dc = win32gui.CreateDC("", monitor_info['Device'], "")
        bits_per_pixel = win32api.GetDeviceCaps(dc, win32con.BITSPIXEL)
        win32gui.DeleteDC(dc)
        # 整理信息
        monitors.append({
            "显示器名称": monitor_info['Device'],
            "宽度(像素)": monitor_info['Monitor'][2] - monitor_info['Monitor'][0],
            "高度(像素)": monitor_info['Monitor'][3] - monitor_info['Monitor'][1],
            "色深(位)": bits_per_pixel,
            "缩放比例(%)": scale_percent
        })
        return True
    win32gui.EnumDisplayMonitors(None, None, enum_monitors_callback, None)
    return monitors

# 打印结果
for idx, monitor in enumerate(get_all_monitor_info(), 1):
    print(f"=== 显示器 {idx} ===")
    for key, value in monitor.items():
        print(f"{key}: {value}")
    print()

内容的提问来源于stack exchange,提问作者user26576465

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 08:30:55