Guest markm75 Posted January 2, 2008 Posted January 2, 2008 Is there a way to do this via VBS script files somehow.. I already install the printer via the vbs script file.. every time they log in.. all 12 versions of our network printers get installed. I'd like a way to avoid installing the printer if it already exists? Thanks in advance..
Guest - Michel Posted January 2, 2008 Posted January 2, 2008 RE: Installing network share printers via vbscript, but only if dont e Hi, I don't know how you (or someone else) built the vb script, but I would start with an If Exist before I would add the printer... More script details are needed if you really want an answer for your situation I'm afraid. (and I think this is more a vbs question than an Windows Server one :-) ) Kind regards, Michel "markm75" wrote: > Is there a way to do this via VBS script files somehow.. > > I already install the printer via the vbs script file.. every time they log > in.. all 12 versions of our network printers get installed. > > I'd like a way to avoid installing the printer if it already exists? > > Thanks in advance.. > >
Guest markm75 Posted January 3, 2008 Posted January 3, 2008 RE: Installing network share printers via vbscript, but only if do RE: Installing network share printers via vbscript, but only if do Through significant trial and error.. i created code that works.. figured i'd share.. 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==================================================
Recommended Posts