Re: vb script to detect if printer is installed and then install it from a list if not? (2003 server vbs)
- From: markm75 <markm75c@xxxxxxx>
- Date: Thu, 3 Jan 2008 08:35:46 -0800 (PST)
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==================================================
.
- Follow-Ups:
- Prev by Date: Re: Executing a command with options
- Next by Date: Re: formatting output to be sorted by largest size
- Previous by thread: Executing a command with options
- Next by thread: Re: vb script to detect if printer is installed and then install it from a list if not? (2003 server vbs)
- Index(es):
Relevant Pages
|