Here is the code i currently use.. as it stands it installs the
printers every time a person logs in.. as i mentioned.. i want to put
a blurb of code that will check if the printer is installed (from a
list of the printers) and install only if not found..
Any thoughts on that code that would be needed?:
i think objPrinter.DeviceID would have to not match any of the
possible printers..
-------------------
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\vsdc02\hplj2200"
WshNetwork.AddWindowsPrinterConnection "\\vsdc02\Phaser"
WshNetwork.AddWindowsPrinterConnection "\\vsdc02\hplj5m"
WshNetwork.AddWindowsPrinterConnection "\\vsdc02\Dell5110"
WshNetwork.AddWindowsPrinterConnection "\\vsdc02\CanonCopier-Fax"
WshNetwork.AddWindowsPrinterConnection "\\vsdc02\CanonCopier-Printer"
WshNetwork.AddWindowsPrinterConnection "\\vsdc01\dell5110"
WshNetwork.AddWindowsPrinterConnection "\\vsdc01\hplj2200"
WshNetwork.AddWindowsPrinterConnection "\\vsdc01\Phaser"
WshNetwork.AddWindowsPrinterConnection "\\vsdc01\hplj5m"
WshNetwork.AddWindowsPrinterConnection "\\vsdc01\CanonCopier-Fax"
WshNetwork.AddWindowsPrinterConnection "\\vsdc01\CanonCopier-Printer"
REM ==== Code to remove stale printers =======
strComputer = "."
strOldServer1 = "\\PSTDC"
strOldServer2 = "\\PSTDC2"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = False")
If colPrinters.Count <> 0 Then
For Each objPrinter In colPrinters
If UCase(objPrinter.ServerName) = UCase(strOldServer1) Then
WshNetwork.RemovePrinterConnection objPrinter.DeviceID, True, True
If UCase(objPrinter.ServerName) = UCase(strOldServer2) Then
WshNetwork.RemovePrinterConnection objPrinter.DeviceID, True, True
rem If Ucase(objPrinter.DeviceID) = UCase("\\vsdc02\hplj2200")
Next
End If
REM ======= END CODE TO REMOVE old printers ============
------------------------
'========= Code to install printers, only if installed!============
'set the array size 1 less than total number (for VB)
'example servers with share names below
Dim arrayPossPrinters(11)
arrayPossPrinters(0) = "\\server2\hplj2200"
arrayPossPrinters(1) = "\\server2\Phaser"
arrayPossPrinters(2) = "\\server2\hplj5m"
arrayPossPrinters(3) = "\\server2\Dell5110"
arrayPossPrinters(4) = "\\server2\CanonCopier-Fax"
arrayPossPrinters(5) = "\\server2\CanonCopier-Printer"
arrayPossPrinters(6) = "\\server1\dell5110"
arrayPossPrinters(7) = "\\server1\hplj2200"
arrayPossPrinters(8) = "\\server1\Phaser"
arrayPossPrinters(9) = "\\server1\hplj5m"
arrayPossPrinters(10) = "\\server1\CanonCopier-Fax"
arrayPossPrinters(11) = "\\server1\CanonCopier-Printer"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = False")
' ====start checking installed printers =====
If colPrinters.Count <> 0 Then
for each objPossPrinter In arrayPossPrinters
bFoundMatch = -1
'check the current installedprinter in the array vs the possible
array list
For Each objPrinterInstalled In colPrinters
'.ShareName is the share ' servername for server
'.DeviceID is the "name" listed in the folder on the server (not
same as sharename)
'**we loop through all possible printers and compare to
the current one in the loop of installed ones
If Ucase(objPrinterInstalled.ServerName & "\" &
objPrinterInstalled.ShareName) = Ucase(objPossPrinter)
Then
bFoundMatch = 1
'break out inner loop
Exit For
End If
Next 'for each obj in colprinters loop
If bFoundMatch = -1 Then
'install printer using objPossPrinter
WshNetwork.AddWindowsPrinterConnection objPossPrinter
End If
' wscript.echo bFoundMatch
Next
End If
'========== end code to install prints only if
installed==================================================
Revised below.. forgot to include the install all option if the count
was zero:
If colPrinters.Count <> 0 Then
bFoundMatch = -1
else 'must have this in case there are none installed locally!
WshNetwork.AddWindowsPrinterConnection "\\server2\hplj2200"
WshNetwork.AddWindowsPrinterConnection "\\server2\Phaser"
WshNetwork.AddWindowsPrinterConnection "\\server2\hplj5m"
WshNetwork.AddWindowsPrinterConnection "\\server2\Dell5110"
WshNetwork.AddWindowsPrinterConnection "\\server2\CanonCopier-Fax"
WshNetwork.AddWindowsPrinterConnection "\\server2\CanonCopier-Printer"
WshNetwork.AddWindowsPrinterConnection "\\server1\dell5110"
WshNetwork.AddWindowsPrinterConnection "\\server1\hplj2200"
WshNetwork.AddWindowsPrinterConnection "\\server1\Phaser"
WshNetwork.AddWindowsPrinterConnection "\\server1\hplj5m"
WshNetwork.AddWindowsPrinterConnection "\\server1\CanonCopier-Fax"
WshNetwork.AddWindowsPrinterConnection "\\server1\CanonCopier-Printer"