Re: Adding Missing printer if they not there
- From: poboy_n.o_style <gryphonfoo@xxxxxxxxxxx>
- Date: Wed, 20 Dec 2006 13:30:01 -0800
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
- Follow-Ups:
- Re: Adding Missing printer if they not there
- From: JimsMind
- Re: Adding Missing printer if they not there
- References:
- Re: Adding Missing printer if they not there
- From: JimsMind
- Re: Adding Missing printer if they not there
- From: poboy_n.o_style
- Re: Adding Missing printer if they not there
- From: JimsMind
- Re: Adding Missing printer if they not there
- Prev by Date: Re: setting user accounts mailbox size limit script
- Next by Date: Re: Retreive reservation range from DHCP server
- Previous by thread: Re: Adding Missing printer if they not there
- Next by thread: Re: Adding Missing printer if they not there
- Index(es):
Relevant Pages
|