/build/static/layout/Breadcrumb_cap_w.png

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


0 Comments   [ + ] Show comments

Answers (2)

Posted by: SMal.tmcc 7 years ago
Red Belt
1
use wmic and run as a kscript to create a file, then read the files in as CIR's

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 7 years ago
Posted by: anonymous_9363 7 years ago
Red Belt
0
Also, remember that printers are user resources, not machine resources so your interrogation needs to be conducted as the logged-in user.

Comments:
  • network printers are user resources while local printers are machine resources - SMal.tmcc 7 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ