Hello everyone!
I found this FAQ and I am trying to implement part of it: ---
Set WSHNetwork = CreateObject("WScript.Network")
'Install only missing printers from predefined list
'Thanks go to DM4Ever for this section
'Create a dictionary to store our printer paths
Set objDictPrnts = CreateObject("Scripting.Dictionary")
objDictPrnts.CompareMode = vbTextCompare
objDictPrnts.Add "\\spidersparlor\HPLaserJet3", "\\spidersparlor\HPLaserJet3"
objDictPrnts.Add "\\spidersparlor\HPLaserJet4", "\\spidersparlor\HPLaserJet4"
objDictPrnts.Add "\\spidersparlor\Accounting", "\\spidersparlor\Accounting"
objDictPrnts.Add "\\spidersparlor\ColorPrinter", "\\spidersparlor\ColorPrinter"
objDictPrnts.Add "\\spidersparlor\tektronics", "\\spidersparlor\tektronics"
' loop through printer connections
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
PrinterPath = WSHPrinters.Item(LOOP_COUNTER +1)
' if the current path exist in our dictionary remove it
If objDictPrnts.Exists(PrinterPath) Then objDictPrnts.Remove PrinterPath
Next
' loop through the path's that were not found and add them
For Each PrinterPath In objDictPrnts.Keys
WSHNetwork.AddWindowsPrinterConnection PrinterPath
Next
--
What I have done is created the dictionary based on the groups the users are in. For example:
--
strArch = Right(wshShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%"), 2)
IF (strArch = 86) Then
strPrintServer = "\\32BitServer\"
strPrintArch = " 32"
End IF
IF (strArch = 64) Then
strPrintServer = "\\64BitServer\"
strPrintArch = " 64"
End IF
If (IsMember(objUser, "PRN_Room_146_Printer") = True) Then
objDictPrnts.Add strPrintServer & "CHS Room 146 Printer" & strPrintArch, strPrintServer & "CHS Room 146 Printer" & strPrintArch
End If
--
So far that all seems to work. I tested my functions by getting the objDictPrnts.Count and it returns the correct number.
The problem is that nothing seems to be working when going through this part
--
' loop through printer connections
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
PrinterPath = WSHPrinters.Item(LOOP_COUNTER +1)
' if the current path exist in our dictionary remove it
If objDictPrnts.Exists(PrinterPath) Then objDictPrnts.Remove PrinterPath
Next
' loop through the path's that were not found and add them
For Each PrinterPath In objDictPrnts.Keys
WSHNetwork.AddWindowsPrinterConnection PrinterPath
Next
--
I am using this on printers that are already on the computer and I get the same count for the array before and after the printers should be deleted from the array. Also, the printers never are mapped to the computers.
The clients are Win7.
I know we can use GP for this but we already have something like this in place, I just want to streamline it (and hopefully fix the issues we are having with the printers not mapping randomly.)
Any help would be appreciated.
Thank you,
Keegan
I found this FAQ and I am trying to implement part of it: ---
Set WSHNetwork = CreateObject("WScript.Network")
'Install only missing printers from predefined list
'Thanks go to DM4Ever for this section
'Create a dictionary to store our printer paths
Set objDictPrnts = CreateObject("Scripting.Dictionary")
objDictPrnts.CompareMode = vbTextCompare
objDictPrnts.Add "\\spidersparlor\HPLaserJet3", "\\spidersparlor\HPLaserJet3"
objDictPrnts.Add "\\spidersparlor\HPLaserJet4", "\\spidersparlor\HPLaserJet4"
objDictPrnts.Add "\\spidersparlor\Accounting", "\\spidersparlor\Accounting"
objDictPrnts.Add "\\spidersparlor\ColorPrinter", "\\spidersparlor\ColorPrinter"
objDictPrnts.Add "\\spidersparlor\tektronics", "\\spidersparlor\tektronics"
' loop through printer connections
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
PrinterPath = WSHPrinters.Item(LOOP_COUNTER +1)
' if the current path exist in our dictionary remove it
If objDictPrnts.Exists(PrinterPath) Then objDictPrnts.Remove PrinterPath
Next
' loop through the path's that were not found and add them
For Each PrinterPath In objDictPrnts.Keys
WSHNetwork.AddWindowsPrinterConnection PrinterPath
Next
--
What I have done is created the dictionary based on the groups the users are in. For example:
--
strArch = Right(wshShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%"), 2)
IF (strArch = 86) Then
strPrintServer = "\\32BitServer\"
strPrintArch = " 32"
End IF
IF (strArch = 64) Then
strPrintServer = "\\64BitServer\"
strPrintArch = " 64"
End IF
If (IsMember(objUser, "PRN_Room_146_Printer") = True) Then
objDictPrnts.Add strPrintServer & "CHS Room 146 Printer" & strPrintArch, strPrintServer & "CHS Room 146 Printer" & strPrintArch
End If
--
So far that all seems to work. I tested my functions by getting the objDictPrnts.Count and it returns the correct number.
The problem is that nothing seems to be working when going through this part
--
' loop through printer connections
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
PrinterPath = WSHPrinters.Item(LOOP_COUNTER +1)
' if the current path exist in our dictionary remove it
If objDictPrnts.Exists(PrinterPath) Then objDictPrnts.Remove PrinterPath
Next
' loop through the path's that were not found and add them
For Each PrinterPath In objDictPrnts.Keys
WSHNetwork.AddWindowsPrinterConnection PrinterPath
Next
--
I am using this on printers that are already on the computer and I get the same count for the array before and after the printers should be deleted from the array. Also, the printers never are mapped to the computers.
The clients are Win7.
I know we can use GP for this but we already have something like this in place, I just want to streamline it (and hopefully fix the issues we are having with the printers not mapping randomly.)
Any help would be appreciated.
Thank you,
Keegan