监视器的序列号

发布于 2025-01-27 18:58:11 字数 243 浏览 3 评论 0原文

我可以使用PowerShell命令从所有附加的显示器中获取序列号:

get-wmiobject wmimonitorid -namespace root\wmi|foreach-object{($_.SerialnumberID|foreach-object{[char]$_}) -join „“}

是否可以使用VBA执行此操作?

我的目的是将序列号添加到Excel(每个单元格一个序列号)。

I can get the serial numbers from all attached monitors with the Powershell command:

get-wmiobject wmimonitorid -namespace root\wmi|foreach-object{($_.SerialnumberID|foreach-object{[char]$_}) -join „“}

Is it possible to do this with VBA?

My intention is to add the serial numbers to Excel (one serial number per cell).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘年祭陌 2025-02-03 18:58:11

您需要将WMI脚本库添加到

Sub getMonitors()
    Dim m As SWbemObject
    Dim c
    For Each m In GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\.\root\WMI").ExecQuery _
        ("SELECT SerialNumberID FROM WmiMonitorID")
        For Each c In m.serialNumberID
            Debug.Print Chr(c);
        Next
        Debug.Print
    Next
End Sub

可以更改debug.print的引用中。要通过使用dim s作为字符串s = s = s + chr(c),将其添加到某些单元格中;

you will need to add WMI scripting library to the references

Sub getMonitors()
    Dim m As SWbemObject
    Dim c
    For Each m In GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\.\root\WMI").ExecQuery _
        ("SELECT SerialNumberID FROM WmiMonitorID")
        For Each c In m.serialNumberID
            Debug.Print Chr(c);
        Next
        Debug.Print
    Next
End Sub

You can change debug.print to add to certain cells instead, by using Dim s as String and s = s + chr(c);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文