我正在尝试获取远程服务器上可用的打印队列列表。
最终需要从ASP.NET执行此操作,但现在我决定使用控制台应用程序。
当我使用远程服务器的路径创建 System.Printing.PrintServer 类的实例时,我能够获得有关打印服务器的基本信息。但是当我调用 GetPrintQueues方法时,我只获得在本地框中定义的队列。无论我用于远程设备。
Imports System.Printing
Module Module1
Sub Main()
ListPrintQueues("\\local")
ListPrintQueues("\\remote")
ListPrintQueues("\\other")
End Sub
Sub ListPrintQueues(ByVal server As String)
Dim ps As New PrintServer(server)
Console.WriteLine("Printer Server=" & ps.Name)
Dim flags() As EnumeratedPrintQueueTypes = {EnumeratedPrintQueueTypes.Connections, EnumeratedPrintQueueTypes.Local}
Dim queues As PrintQueueCollection = ps.GetPrintQueues(flags)
For Each pq As PrintQueue In queues
Console.WriteLine(pq.FullName)
Next
Console.WriteLine()
End Sub
End Module
假设以下配置
结果是:
Print Server=\\local \\local\LPrinter1 \\local\LPrinter2 \\remote\RPrinter1 Print Server=\\remote \\remote\RPrinter1 Print Server=\\other \\remote\RPrinter1
我最好的猜测是,在GetPrintQueues()方法中发生了一些事情,导致打印服务器被重置为本地盒,因为无论打印服务器名称是什么,只要它是一个有效的计算机就可以了。网络
答案 0 :(得分:1)
发现答案......即使这不是我想要的。
如果我将枚举标志更改为仅本地和连接到我以前登录过的服务器,我将获得正确的打印机。但如果我没有登录,那么我会从我的机器上获得远程打印队列列表。
当我尝试使用WMI执行类似操作时,我在连接到的远程服务器上出现“拒绝访问”错误。我的猜测是System.Printing正在捕获异常,然后默认为本地打印服务器。
Imports System.Printing
Module Module1
Sub Main()
ListPrintQueues("\\local")
ListPrintQueues("\\remote")
ListPrintQueues("\\other")
End Sub
Sub ListPrintQueues(ByVal server As String)
Dim ps As New PrintServer(server)
Console.WriteLine("Printer Server=" & ps.Name)
Dim flags() As EnumeratedPrintQueueTypes = {EnumeratedPrintQueueTypes.Local}
Dim queues As PrintQueueCollection = ps.GetPrintQueues(flags)
For Each pq As PrintQueue In queues
Console.WriteLine(pq.FullName)
Next
Console.WriteLine()
End Sub
End Module
答案 1 :(得分:0)
Private Sub btnreanudar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnreanudar.Click
Dim SERVIDOR As New System.Printing.PrintServer() 'SUPERIOR DEL SISTEMA DE IMPRESION (EL ORDENADOR)
Dim IMPRESORAS As PrintQueueCollection = SERVIDOR.GetPrintQueues() 'IMPRESORAS DISPONIBLES
For Each IMPRESORA As PrintQueue In IMPRESORAS 'RECORRE TODAS LAS IMPRESORAS
Try
If IMPRESORA.NumberOfJobs > 0 Then 'SI LA IMPRESORA TIENE ALGUNA IMPRESION EN MARCHA......
IMPRESORA.Refresh()
Dim IMPRESIONES As PrintJobInfoCollection = IMPRESORA.GetPrintJobInfoCollection() 'CREA UNA COLECCION DE IMPRESIONES EN MARCHA
For Each IMPRESION In IMPRESIONES ' POR CADA IMPRESION......
If IMPRESION.JobIdentifier = joblist.CurrentRow.Cells("JobId").Value Then
IMPRESION.Resume()
Exit Sub
End If
Next
End If
Catch ex As Exception
End Try
Next
End Sub