On Dec 22, 1:34*pm, freddy <fre...@newsgroup> wrote:
> I have a script that works ok for the most part, I still need to add moreto
> map the other 5 printers. Here is the script:
> {snip}
> Is there an easier way to add the script section or do I have to add it 5
> more times to add the rest of the printers You can build an array or dictionary to contain the parameters and
then select the array elements based on the selected option, something
like this ...
<script language="VBScript">
Dim aPrtParams, objWMIService
Const PortName = 0, PortProtocol=1, PortHostAddr=2, PortNumb=3,
PortSNMP=4
Const DrvrName = 5, DrvrPltfrm=6, DrvrVersion=7, DrvrPath=8,
DrvrInfname=9,loc=10
Sub Window_Onload
window.resizeTo 600,400
document.body.bgColor="green"
aPrtParams = Array( _
"IP_10.176.29.58,1,10.176.29.58,9100,False," _
& "Xerox WorkCentre 7345 PCL6,Windows NT,1.0," _
& "\\lmtsinst\ctinstalls$\TOOLS_&_UTILITIES
\XPSP2_I386\I386," _
& "C:\Xerox\x2GPINX.inf,Main Printer", _
"IP_10.176.29.XX,1,10.176.29.XX,9100,False," _
& "Bay Bridge,Windows NT,1.0," _
& "\\lmtsinst\ctinstalls$\TOOLS_&_UTILITIES
\XPSP2_I386\I386," _
& "C:\Someplace\Some.inf,remembertheMain Printer", _
"IP_10.176.29.XX,1,10.176.29.XX,9100,False," _
& "Golden Gate,Windows NT,1.0," _
& "\\lmtsinst\ctinstalls$\TOOLS_&_UTILITIES
\XPSP2_I386\I386," _
& "C:\Anotherplace\Another.inf,notMain Printer", _
"IP_10.176.29.XX,1,10.176.29.XX,9100,False," _
& "Union Square,Windows NT,1.0," _
& "\\lmtsinst\ctinstalls$\TOOLS_&_UTILITIES
\XPSP2_I386\I386," _
& "C:\UnionSQplace\UnionSQ.inf,subMain Printer" _
)
strComputer = "."
' Only need to instantiate this once
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root
\cimv2")
End Sub
Sub RunScript
aSelected = Split(aPrtParams(listbox.Value - 1), ",")
' Adding an IP
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
with objNewPort
.Name = aSelected(PortName)
.Protocol = aSelected(PortProtoco)
.HostAddress = aSelected(PortHostAddr)
.PortNumber = aSelected(PortNumb)
.SNMPEnabled = CBool(aSelected(PortSNM))
.Put_
end with ' objNewPort
'Add driver
objWMIService.Security_.Privileges.AddAsString
"SeLoadDriverPrivilege", True
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
with objDriver
.Name = aSelected(DrvrName)
.SupportedPlatform = aSelected(DrvrPltfrm)
.Version = aSelected(DrvrVersion)
.DriverPath = aSelected(DrvrPath)
.Infname = aSelected(DrvrInfname)
intResult = .AddPrinterDriver(objDriver)
end with ' objDriver
'Creating printer
Set objPrinter = objWMIService.Get
("Win32_Printer").SpawnInstance_
with objPrinter
.DriverName = objDriver.Name
.PortName = objNewPort.Name
.DeviceID = objDriver.Name
.Location = aSelected(loc)
.Network = True
.Put_
end with ' objPrinter
End Sub
I tested the part I added, but assumed the rest worked (though I did
mess with it, but hopefully it still works - no syntax errors
reported, anyway).
_____________________
Tom Lavedas