Re: vb script to detect if printer is installed and then install it from a list if not? (2003 server vbs)

Tech-Archive recommends: Fix windows errors by optimizing your registry



Others may find this useful.. after significant trial and error.. i
found the looping that works.. here is the code.. Enjoy!:



'========= 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==================================================
.



Relevant Pages

  • RE: Installing network share printers via vbscript, but only if do
    ... 'set the array size 1 less than total number ... 'example servers with share names below ... '**we loop through all possible printers and compare to the ...
    (microsoft.public.windows.server.general)
  • re: stuck on first time using JSON
    ... transfer to the server. ... But, I am still new to javascript, and am having a problem with how to ... I will end up having an array of arrays by the time I am done though, ... JSONobject from within a loop? ...
    (comp.lang.javascript)
  • Re: Pick items from an array
    ... > but once you get to the fifth server in the CSV you want it to loop back to ... >> What I'm trying to do is have an array of four AD servers. ... the next server on the csv dile will pick the next server ...
    (microsoft.public.windows.server.scripting)
  • Re: vb script to detect if printer is installed and then install it from a list if not? (2003 server
    ... forgot to include the install all option if the count ... 'set the array size 1 less than total number ... '.ShareName is the share ' servername for server ... '**we loop through all possible printers and compare to ...
    (microsoft.public.scripting.vbscript)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)