vba 通过 CMD 获取 HP 打印机序列号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23110007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:47:07  来源:igfitidea点击:

get HP Printer Serial Number via CMD

vbavbscriptcmdprinters

提问by nbnlko

Is there any way to gather Serial Number info for HP Printers on Windows using only the CMD? I don't need a third party tool. What I need is to be able to query them from CMD. For the workstations I use the [wmic /node:COMPUTER bios get serialnumber] command to get what I want. I was wondering if there's a way, a script of some kind that could perform the same action.

有什么方法可以仅使用 CMD 在 Windows 上收集 HP 打印机的序列号信息?我不需要第三方工具。我需要的是能够从 CMD 查询它们。对于工作站,我使用 [wmic /node:COMPUTER bios get serialnumber] 命令来获取我想要的东西。我想知道是否有办法,某种可以执行相同操作的脚本。

Thanks

谢谢

回答by AWS-Cloud-Architect-Rob

I cannot find an option to include the serial number as it is not supported by the vbscript Win32_Printer class, however you may be able to retrieve unique information from this script.

我找不到包含序列号的选项,因为 vbscript Win32_Printer 类不支持它,但是您可以从此脚本中检索唯一信息。

Win32_Printer Class

Win32_Printer 类

Option Explicit

选项显式

Dim objWMIService
Dim objItem
Dim colItems
Dim strComputer
DIm intPrinters

strComputer ="."


    ' Pure WMI Section
    Set objWMIService = GetObject _
    ("winmgmts:\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Printer")



    ' On Error Resume Next
    For Each objItem In colItems

        If(objItem.name = "HP") Then

        WScript.Echo (objItem.name)
        WScript.Echo (objItem.Description) 
        WScript.Echo (objItem.DeviceID)
        WScript.Echo (objItem.DriverName)

        End If  

    Next

'Release Memory
Set objItem = Nothing
Set objWMIService = Nothing
Set colItems = Nothing

WScript.Quit