通过WMI查找所有监视器的所有可能屏幕分辨率



如何在WMI查询中执行此操作?

尝试首先直接在VideoModeDescriptor类上使用查询,但只有在实例化时才能访问。尝试了InstancesOf,如下AutoHotkey片段所示:

Enabled := ComObjError(1)
wmi := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\" A_ComputerName "rootwmi")
Instances := wmi.InstancesOf("VideoModeDescriptor", 1)
For Instance In Instances
msgbox % Instance.CompositePolarityType ; e.g. test first element

没有成功,但是它有可能与这里描述的GetObject一起使用。因此,查询WmiMonitorListedSupportedSourceMode的另一个选项是更好的方法,但如何获得原始分辨率数据呢?

AHK的完整解决方案是:

wmi := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\" A_ComputerName "rootwmi")
for monitor in wmi.ExecQuery("SELECT NumOfMonitorSourceModes, MonitorSourceModes FROM WmiMonitorListedSupportedSourceModes WHERE Active=TRUE",,wbemFlagForwardOnly := 32)
{
modes := ""
Loop, % monitor.NumOfMonitorSourceModes - 1
modes .= monitor.MonitorSourceModes[A_Index - 1].HorizontalActivePixels . " " . monitor.MonitorSourceModes[A_Index - 1].HorizontalImageSize . " "
msgbox % monitor.InstanceName . "`n" . modes

有趣的是,标准的For Each键,值迭代为monitor生成了空白,而rootcimv2的代码由于无效类错误而失败。即使在原始查询中没有指定CCD_ 5,CCD_
下面的vbscript代码只产生首选的分辨率,但很容易将上述技术应用于所有分辨率:

strComputer = "."
strQuery = "SELECT PreferredMonitorSourceModeIndex, NumOfMonitorSourceModes, MonitorSourceModes " & _
"FROM WmiMonitorListedSupportedSourceModes"
Set objWMIService = GetObject("winmgmts:\" & strComputer & "ROOTWMI")
Set colItems = objWMIService.ExecQuery(strQuery, , 48)
For Each objItem In colItems
intIndex = objItem.PreferredMonitorSourceModeIndex
msgbox("NumOfMonitorSourceModes: " & objItem.NumOfMonitorSourceModes & _
Replace("nInstanceName: ", "n", vbLf) & objItem.InstanceName & _
Replace("nHorizontal: ", "n", vbLF) & objItem.MonitorSourceModes(intIndex).HorizontalActivePixels & _
Replace("nVertical: ", "n", vbLF) & objItem.MonitorSourceModes(objIintIndex).VerticalActivePixels)
Next

相关内容

  • 没有找到相关文章

最新更新