From: freddy on 22 Dec 2009 13:34 I have a script that works ok for the most part, I still need to add more to map the other 5 printers. Here is the script: <html> <head> <title>Map Printer</title> <HTA:APPLICATION ID="oMyApp" APPLICATIONNAME="Map printer" Border="thin" CAPTION="yes" ICON="Printer.ico" SHOWINTASKBAR="yes" SINGLEINSTANCE="yes" SYSMENU="Yes" SCROLL="no" MAXIMIZEBUTTON="NO" </head> <script language="VBScript"> Sub Window_Onload window.resizeTo 600,400 document.body.bgColor="green" End Sub Sub RunScript ' Adding an IP If listbox.Value = 1 Then strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objNewPort = objWMIService.Get _ ("Win32_TCPIPPrinterPort").SpawnInstance_ objNewPort.Name = "IP_10.176.29.58" objNewPort.Protocol = 1 objNewPort.HostAddress = "10.176.29.58" objNewPort.PortNumber = "9100" objNewPort.SNMPEnabled = False objNewPort.Put_ 'Add driver Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True Set objDriver = objWMIService.Get("Win32_PrinterDriver") objDriver.Name = "Xerox WorkCentre 7345 PCL6" objDriver.SupportedPlatform = "Windows NT" objDriver.Version = "1.0" objDriver.DriverPath = "\\lmtsinst\ctinstalls$\TOOLS_&_UTILITIES\XPSP2_I386\I386" objDriver.Infname = "C:\Xerox\x2GPINX.inf" intResult = objDriver.AddPrinterDriver(objDriver) 'Creating printer Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_ objPrinter.DriverName = "Xerox WorkCentre 7345 PCL6" objPrinter.PortName = "IP_10.176.29.58" objPrinter.DeviceID = "Xerox WorkCentre 7345 PCL6" objPrinter.Location = "Main Printer" objPrinter.Network = True objPrinter.Put_ End If End Sub Sub CancelScript Self.Close() End Sub </SCRIPT> <BODY> <br> <P><center><b>Please Select the printer to install from the drop-down listbox</b></center></P> <br> <P ALIGN=CENTER><select size="1" name="listbox" onChange="RunScript"> <option value="1">Xerox WorkCentre 7345</option> <option value="2">Bay Bridge</option> <option value="3">Golden Gate</option> <option value="4">Union Square</option> </select> <br> <br> <P ALIGN=CENTER><input id=runbutton class="button" type="button" value="Install Printer" name="ok_button" onClick="RunScript"> <P ALIGN=CENTER><input id=runbutton class="button" type="button" value="Cancel" name="cancel_button" onClick="CancelScript"> </BODY> 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
From: Tom Lavedas on 22 Dec 2009 16:11 On Dec 22, 1:34 pm, freddy <fre...(a)discussions.microsoft.com> wrote: > I have a script that works ok for the most part, I still need to add more to > 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
|
Pages: 1 Prev: access denied getobject Next: Trying to run a non-Win32 Application |