Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

show network printers mapped

Status
Not open for further replies.

tltechie

Technical User
Apr 25, 2011
17
US
I am trying to show the printers mapped to a computer. I only want the network printers to show up not the local ones. This script will show them but it also shows the document writers and other misc crap i dont want. Any ideas would help.


Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=Impersonate}!\\" & RemoteMachine & "\root\cimv2")
Set ColInstalledPrinters = objWMIService.ExecQuery ("Select * From Win32_Printer")

For Each objPrinter in ColInstalledPrinters
Select Case objPrinter.PrinterStatus
Case 1
StrPrinterStatus = "Other"
Case 2
StrPrinterStatus = "Unknown"
Case 3
StrPrinterStatus = "Idle"
Case 4
StrPrinterStatus = "Printing"
Case 5
StrPrinterStatus = "Warmup"
End Select
StrPrintStatus = StrPrintStatus & "Name: " & objPrinter.Name & VbCrLf
StrPrintStatus = StrPrintStatus & "Location: " & objPrinter.Location & VbCrLf
StrPrintStatus = StrPrintStatus & "Printer Status: " & StrPrinterStatus & VbCrLf
StrPrintStatus = StrPrintStatus & "Server Name: " & objPrinter.ServerName & VbCrLf
StrPrintStatus = StrPrintStatus & "Share Name: " & objPrinter.ShareName & VbCrLf
StrPrintStatus = StrPrintStatus & VbCrLf
If objPrinter.Name = "Microsoft Office Document Image Writer" Then
Else

End If
next
 
You pretty much have it. Collect by .Name

Network printers are connected to the local computer using the UNC path to the printer. This usually consists of an IP or server name and can be returned using objPrinter.Name. Simply look for that server name or IP in the UNC.

A network printer will have a .Name of "\\server\printerName". A local printer or document writer won't have a UNC path and will typically consist of the model name (eg "HP Deskjet 6940 series").

Code:
strServer = "myPrintServer"  [green]'Server name or IP[/green]
if (inStr(objPrinter.Name, "\\" & strServer)) then
   'this is a network printer
end if

-Geates





"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom
 
What if we are working with an unknown server and just trying to get the information for the network printer.
 
If InStr(objPrinter.Name, "\\") Then
'this is a network printer
MsgBox objPrinter.Name
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top