CAIMINHO DE REDE DE UMA IMPRESSORA

USUARIO.EXCLUIDOS 05/04/2004 17:50:48
#18965
é o seguinte: Tenho algumas impressoras instaladas em rede. Preciso obter, de uma dada impressora, o caminho em que ela está instalada. Por exemplo: \\servidor\impressora.

Uso a coleção Printers para listar as impresoras, mas nenhum dos métodos desta coleção me retorna isso que eu quero. Como fazer? Existe alguma API? Qual é e como usá-la?
USUARIO.EXCLUIDOS 06/04/2004 10:38:06
#19044
Resposta escolhida
Esse NE01: que está aparecendo é relacionado á um spool do windows, criado por um ou mais servidores de impressão. Verifique a propriedade DriverName do objeto Printer.
Você terá de saber as configurações para poder mapear essa informação, pois podem estar armazenadas em um servidor de rede. Ou ainda, por meio do(s) manual(is) do(s) servidor(es) de impressão.
USUARIO.EXCLUIDOS 06/04/2004 12:34:27
#19084
Não sei se será útil, mas dê uma olhada neste grupinho:

Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function PrinterProperties Lib "winspool.drv" (ByVal hwnd As Long, ByVal hPrinter As Long) As Long

'Testando
Private Sub Form_Load()
Dim oP as Printer
Dim hPrinter As Long
For Each oP in Printers
OpenPrinter oP.DeviceName, hPrinter, ByVal 0&
PrinterProperties Me.hwnd, hPrinter
ClosePrinter hPrinter
Next
hPrinter = Empty
Set oP = Nothing
End Sub
USUARIO.EXCLUIDOS 06/04/2004 12:43:43
#19086
Pode juntar com alguma informação das portas, não apenas selecionar e configurar. Por exemplo, complementando o anterior:

Option Explicit

Private Type PORT_INFO_2
pPortName As String
pMonitorName As String
pDescription As String
fPortType As Long
Reserved As Long
End Type
Private Type API_PORT_INFO_2
pPortName As Long
pMonitorName As Long
pDescription As Long
fPortType As Long
Reserved As Long
End Type

Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function PrinterProperties Lib "winspool.drv" (ByVal hwnd As Long, ByVal hPrinter As Long) As Long
Private Declare Function EnumPorts Lib "winspool.drv" Alias "EnumPortsA" (ByVal pName As String, ByVal Level As Long, ByVal lpbPorts As Long, ByVal cbBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long
Dim Ports(0 To 100) As PORT_INFO_2
Public Function TrimStr(strName As String) As String
Dim x As Integer
x = InStr(strName, vbNullChar)
If x 0 Then TrimStr = Left(strName, x - 1) Else TrimStr = strName
End Function
Public Function LPSTRtoSTRING(ByVal lngPointer As Long) As String
Dim lngLength As Long
lngLength = lstrlenW(lngPointer) * 2
LPSTRtoSTRING = String(lngLength, 0)
CopyMem ByVal StrPtr(LPSTRtoSTRING), ByVal lngPointer, lngLength
LPSTRtoSTRING = TrimStr(StrConv(LPSTRtoSTRING, vbUnicode))
End Function
Public Function GetAvailablePorts(ServerName As String) As Long
Dim ret As Long
Dim PortsStruct(0 To 100) As API_PORT_INFO_2
Dim pcbNeeded As Long
Dim pcReturned As Long
Dim TempBuff As Long
Dim i As Integer
ret = EnumPorts(ServerName, 2, TempBuff, 0, pcbNeeded, pcReturned)
TempBuff = HeapAlloc(GetProcessHeap(), 0, pcbNeeded)
ret = EnumPorts(ServerName, 2, TempBuff, pcbNeeded, pcbNeeded, pcReturned)
If ret Then
CopyMem PortsStruct(0), ByVal TempBuff, pcbNeeded
For i = 0 To pcReturned - 1
Ports(i).pDescription = LPSTRtoSTRING(PortsStruct(i).pDescription)
Ports(i).pPortName = LPSTRtoSTRING(PortsStruct(i).pPortName)
Ports(i).pMonitorName = LPSTRtoSTRING(PortsStruct(i).pMonitorName)
Ports(i).fPortType = PortsStruct(i).fPortType
Next
End If
GetAvailablePorts = pcReturned
If TempBuff Then HeapFree GetProcessHeap(), 0, TempBuff
End Function

'Testando
Private Sub Form_Load()
Dim oP As Printer
Dim hPrinter As Long
Dim NumPorts As Long
Dim i As Integer
For Each oP In Printers
OpenPrinter oP.DeviceName, hPrinter, ByVal 0&
PrinterProperties Me.hwnd, hPrinter
ClosePrinter hPrinter
Next
NumPorts = GetAvailablePorts("")
Me.AutoRedraw = True
For i = 0 To NumPorts - 1
Me.Print Ports(i).pPortName & Ports(i).pDescription & Ports(i).fPortType & Ports(i).pMonitorName
Next
hPrinter = Empty
Set oP = Nothing
End Sub
USUARIO.EXCLUIDOS 06/04/2004 15:33:08
#19115
Hehe, isso é bom.
Agora, se não lhe restam mais dúvidas quanto á isso, encerre o tópico, ok?
Tópico encerrado , respostas não são mais permitidas