Script to find network printers and default printer
Hello,
I have a script that finds the network printers and stores them. I want the script to tell me which one in the default printer. Weather its a network or stand alone printer(usb) as default
Const ForWriting = 2
Set objNetwork = CreateObject("Wscript.Network")
strName = objNetwork.UserName
strDomain = objNetwork.UserDomain
strUser = strDomain & "\" & strName
strText = strUser & vbCrLf
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = FALSE")
For Each objPrinter in colPrinters
strText = strText & objPrinter.Name & vbCrLf
Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile _
("C:\kbox\Printers.txt", ForWriting, True)
objFile.Write strText
objFile.Close
Answers (2)
here are the 3 wmic calls I run, the first is network only, the second is local only, the third is both.
wmic printer where 'network="true"' get name, default, network > C:\ProgramData\Dell\KACE\user\NetworkPrinters.txt
wmic printer where "network=false and NOT DriverName LIKE '%%WebEx%%' and NOT DriverName LIKE '%%Amyuni%%' and NOT DriverName LIKE '%%Microsoft%%' and NOT DriverName LIKE '%%PDF%%' and NOT DriverName LIKE '%%Adobe%%' and NOT DriverName LIKE '%%Hyland%%' and NOT DriverName LIKE '%%snagit%%'" get name,drivername,printerstatus,default > C:\ProgramData\Dell\KACE\user\LocalPrinters.txt
wmic printer where "NOT DriverName LIKE '%%WebEx%%' and NOT DriverName LIKE '%%Amyuni%%' and NOT DriverName LIKE '%%Microsoft%%' and NOT DriverName LIKE '%%PDF%%' and NOT DriverName LIKE '%%Adobe%%' and NOT DriverName LIKE '%%Hyland%%' and NOT DriverName LIKE '%%snagit%%'" get name,drivername,portname, default > C:\ProgramData\Dell\KACE\user\AllPrinters.txt
http://www.itninja.com/blog/view/create-cirs-to-show-current-users-mapped-drives-and-networled-printers-presented-at-dell-world-user-forum-2014-lessions-from-the-field
also see
http://www.itninja.com/blog/view/k1000-custom-inventory-rule-to-inventory-local-network-printers
Comments:
-
of course the not like commands need to be tuned for your environment to remove those crappy not really a printer printers windows installs - SMal.tmcc 8 years ago
Comments:
-
network printers are user resources while local printers are machine resources - SMal.tmcc 8 years ago