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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for local USB Printer

Status
Not open for further replies.

jgus

Technical User
Aug 3, 2001
15
US
We have two different model local USB printer that are used in our environment. We have both printer drivers set up on our images. Is there a way that a script can check to see which of the two printers is connected to the workstation? If I can pull that info then I can easily script to automatically set it as the default at login.
 
Using WMI you can enum the printer objects and search for whichever is listed as Online.

I hope you find this post helpful.

Regards,

Mark
 
The script I was looking for is below. It shows me what devices are currently connected to the USB ports. I can then see which printer is attached locally and through script automatically change the default printer to the correct printer object.

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDevices = objWMIService.ExecQuery ("Select * From Win32_USBControllerDevice")

For Each objDevice in colDevices
strDeviceName = objDevice.Dependent
strQuotes = Chr(34)
strDeviceName = Replace(strDeviceName, strQuotes, "")
arrDeviceNames = Split(strDeviceName, "=")
strDeviceName = arrDeviceNames(1)
Set colUSBDevices = objWMIService.ExecQuery ("Select * From Win32_PnPEntity Where DeviceID = '" & strDeviceName & "'")
For Each objUSBDevice in colUSBDevices
Wscript.Echo objUSBDevice.Description
Next
Next
 
thanks for posting your solution, especially interesting is the link from the USB class to the PnPEntity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top