I have a user that wants to have her local desktop printer the default printer when she logs in to our terminal server. I had created a simple login script for this
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "HP LaserJet 6P (redirected 3)"
The problem with this is that, for whatever reason, the printer name keeps changing the last digit. HP LaserJet 6P (redirected), HP LaserJet 6P (redirected 2), and HP LaserJet 6P (redirected 1) are all examples of how the printer shows up.
I don't know VBScript well enough to account for these changes and am hoping someone will help me to find which variation of the name is being used, and set that as the default printer.
I found a snippet that may help, but I'm unsure how to properly implement it.
Function printerExists(str)
printerExists = False
Dim objWMIService
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Dim colPrinters
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
Dim objPrinter
For Each objPrinter In colPrinters
If objPrinter.Name = str Then
printerExists = True
Exit For
End If
Next
End Function