WMI查询选择所有打印机纸张尺寸vb6

发布于 2024-10-30 13:04:22 字数 288 浏览 0 评论 0 原文

请帮助我选择所有打印机纸张尺寸及其名称包含在 vb6 中。我已经可以使用此代码选择所有打印机,并将其放入列表框中。

Set WMIService = GetObject("winmgmts:\\" & Computer & "\root\cimv2")
Set Items = WMIService.ExecQuery("Select * from Win32_Printer", , 48)

我需要的是一个代码来选择我选择的打印机的所有纸张尺寸/名称,并将其放入另一个列表框中

please i need help in selecting all printer paper sizes with its name included in vb6. i already can select all printer using this code, and put it in a listbox.

Set WMIService = GetObject("winmgmts:\\" & Computer & "\root\cimv2")
Set Items = WMIService.ExecQuery("Select * from Win32_Printer", , 48)

what i need is a code to select all paper size/names of a printer i select, and put it in another listbox

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

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

发布评论

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

评论(2

熊抱啵儿 2024-11-06 13:04:22

WMI 是一种管理脚本服务,应用程序不应依赖其存在和运行。不过,有一些非常好的方法可以直接获取信息。

这是一个带有两个列表框的示例表单:

Option Explicit

Private Const DC_PAPERNAMES = 16

Private Declare Function DeviceCapabilities Lib "winspool.drv" _
    Alias "DeviceCapabilitiesW" ( _
    ByVal lpDeviceName As Long, _
    ByVal lpPort As Long, _
    ByVal iIndex As Long, _
    ByVal lpOutput As Long, _
    ByVal lpDevMode As Long) As Long

Private Sub Form_Load()
    Dim P As Printer

    For Each P In Printers
        lstPrinters.AddItem P.DeviceName
    Next
End Sub

Private Sub lstPrinters_Click()
    Dim P As Printer
    Dim lngPapers As Long
    Dim strPaperNames As String
    Dim lngPaper As Long
    Dim strPaperName As String
    Dim lngActualLength As Long

    Set P = Printers(lstPrinters.ListIndex)
    lngPapers = DeviceCapabilities(StrPtr(P.DeviceName), _
                                   StrPtr(P.Port), _
                                   DC_PAPERNAMES, _
                                   0, _
                                   0)
    strPaperNames = String$(lngPapers * 64, 0)
    lngPapers = DeviceCapabilities(StrPtr(P.DeviceName), _
                                   StrPtr(P.Port), _
                                   DC_PAPERNAMES, _
                                   StrPtr(strPaperNames), _
                                   0)
    lstPapers.Clear
    For lngPaper = 0 To lngPapers - 1
        strPaperName = Mid$(strPaperNames, 64 * lngPaper + 1, 64)
        lngActualLength = InStr(strPaperName, vbNullChar) - 1
        If lngActualLength > 1 Then strPaperName = Left$(strPaperName, lngActualLength)
        lstPapers.AddItem strPaperName
    Next
End Sub

您还可以使用类似的调用检索“纸张尺寸代码”或以毫米为单位的尺寸。请参阅 DeviceCapability 函数

WMI is an admin scripting service that applications should not rely on being present and running. There are perfectly good ways to get the information directly though.

This is a sample Form with two ListBoxes:

Option Explicit

Private Const DC_PAPERNAMES = 16

Private Declare Function DeviceCapabilities Lib "winspool.drv" _
    Alias "DeviceCapabilitiesW" ( _
    ByVal lpDeviceName As Long, _
    ByVal lpPort As Long, _
    ByVal iIndex As Long, _
    ByVal lpOutput As Long, _
    ByVal lpDevMode As Long) As Long

Private Sub Form_Load()
    Dim P As Printer

    For Each P In Printers
        lstPrinters.AddItem P.DeviceName
    Next
End Sub

Private Sub lstPrinters_Click()
    Dim P As Printer
    Dim lngPapers As Long
    Dim strPaperNames As String
    Dim lngPaper As Long
    Dim strPaperName As String
    Dim lngActualLength As Long

    Set P = Printers(lstPrinters.ListIndex)
    lngPapers = DeviceCapabilities(StrPtr(P.DeviceName), _
                                   StrPtr(P.Port), _
                                   DC_PAPERNAMES, _
                                   0, _
                                   0)
    strPaperNames = String$(lngPapers * 64, 0)
    lngPapers = DeviceCapabilities(StrPtr(P.DeviceName), _
                                   StrPtr(P.Port), _
                                   DC_PAPERNAMES, _
                                   StrPtr(strPaperNames), _
                                   0)
    lstPapers.Clear
    For lngPaper = 0 To lngPapers - 1
        strPaperName = Mid$(strPaperNames, 64 * lngPaper + 1, 64)
        lngActualLength = InStr(strPaperName, vbNullChar) - 1
        If lngActualLength > 1 Then strPaperName = Left$(strPaperName, lngActualLength)
        lstPapers.AddItem strPaperName
    Next
End Sub

You could also retrieve "paper size codes" or dimensions in millimeters using a similar call. See DeviceCapabilities Function.

開玄 2024-11-06 13:04:22

Smith, you only need to access the PaperSizesSupported and/or PaperTypesAvailable properties of the Win32_Printer wmi class, both properties are arrays.

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