Re: Adding Missing printer if they not there



I edited the script but it keeps erroring on line 38, any reason why
Const T = 1
Const F = 0

Dim Printer(2,3)
'DIM Printer(5,3) would be for 5 printers.
'Printer() Dimensions:0= TF(Attach); 1= UNC Path; 2= TF(Attached)
Printer(0,1) = "\\server\printera"
Printer(0,0) = T
Printer(0,2) = F
Printer(1,1) = "\\server\printerB"
Printer(1,0) = T
Printer(1,2) = F
Printer(2,1) = "\\server\printerC"
Printer(2,0) = T
Printer(2,2) = F

'Bind to the WMI service on the local machine to collect information
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colPrinters = objWMIService.ExecQuery ("Select * From Win32_Printer")

For Each objPrinter in colPrinters
CurrPrint = Replace(objPrinter.Name, " ", "")
If Left(CurrPrint,2) = "\\" Then
For CheckPrint = 0 to Ubound(Printer)
If Printer(CheckPrint,1) = CurrPrint Then
Printer(CheckPrint,2) = 1
Exit For
End If
Next
End If
Next
For ConPrint = 0 To Ubound(Printer)
If Err.Number Then ErrHandler(826)
If Printer(ConPrint,0) = 1 Then
If Printer(ConPrint,2) = 0 Then
objNetwork.AddWindowsPrinterConnection Printer(ConPrint,1)
If LogStatus = T Then LogEntry("Connecting Printer " &
Printer(ConPrint,1))
Else
If LogStatus = T Then LogEntry(Printer(ConPrint,1) & "
already connected")
End If
End If
Next


I used an Array to do this very thing. I know, it is too dirty, but it
works so I am just leaving it for now! I believe I got the basic logic
from the ms scripting guys. I use this script to assign all network
resources so I may do some things you don't need.

Const T = 1
Const F = 0

Dim Printer(2,3)
'Printer() Dimensions:0= TF(Attach); 1= UNC Path; 2= TF(Attached)
Printer(0,1) = "\\server\Printera"
Printer(0,0) = T
Printer(0,2) = F
Printer(1,1) = "\\server\PrinterB"
Printer(1,0) = T
Printer(1,2) = F
Printer(2,1) = "\\server\PrinterC"
Printer(2,0) = T
Printer(2,2) = F

So here I made the array, the first and last dimension of each record
are simple true or false using a 0 or 1 (I like to use the T or F for
better readability). That way during my data collection and analasys I
can simpy flip the switches on or off as needed. The 0 location stores
the true or false that I look at later to know if I should attach it at
all. The 2 location stores the true or false that i look at later to
see if the printer is already connected.

'Bind to the WMI service on the local machine to collect information
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")

Set colPrinters = objWMIService.ExecQuery ("Select * From
Win32_Printer")

For Each objPrinter in colPrinters
CurrPrint = Replace(objPrinter.Name, " ", "")
If Left(CurrPrint,2) = "\\" Then
For CheckPrint = 0 to Ubound(Printer)
If Printer(CheckPrint,1) = CurrPrint Then
Printer(CheckPrint,2) = 1
Exit For
End If
Next
End If
Next

Here, we checked the machine and found all printers installed, then we
checked only the network printers against our list to see if any of our
network printers are already present, and if they are we set our
connected switch to true.

For ConPrint = 0 To Ubound(Printer)
If Err.Number Then ErrHandler(826)
If Printer(ConPrint,0) = 1 Then
If Printer(ConPrint,2) = 0 Then
objNetwork.AddWindowsPrinterConnection
Printer(ConPrint,1)
If LogStatus = T Then LogEntry("Connecting Printer " _
& Printer(ConPrint,1))
Else
If LogStatus = T Then LogEntry(Printer(ConPrint,1) _
& " already connected")
End If
End If
End If
Next

Finally, at the end of my script, I simply check the true/false lines
and add accordingly.

Hope This helps

James
Just some guy




.



Relevant Pages

  • Need to remove network printers but not mapped printers
    ... I am renaming my network printers and have tested this script and it removes ... Set WSHNetwork = CreateObject ... Then I use this script to map a renamed printer such as CA - HP LaserJet ...
    (microsoft.public.scripting.wsh)
  • Re: Adding Missing printer if they not there
    ... But if this is your entire script, ... connecting to network printers). ... Const T = 1 ... checked only the network printers against our list to see if any of our ...
    (microsoft.public.windows.server.scripting)
  • Re: script to map network and default printers
    ... I figured the network printers should map and if it works correctly, ... The script I used before was simple but it only mapped network printers. ... I placed the script in the logon under group policy where I mapped ...
    (microsoft.public.scripting.vbscript)
  • Re: Adding Missing printer if they not there
    ... But if this is your entire script, ... connecting to network printers). ... Const T = 1 ... checked only the network printers against our list to see if any of our ...
    (microsoft.public.windows.server.scripting)
  • Start up scripts
    ... I want to create a script for my users that will install ... network printers so that it will re-map the printers ... everytime the users log in. ...
    (microsoft.public.windowsxp.network_web)