Windows Vista Forums

HTA VBscript MapIP Printing
  1. #1


    freddy Guest

    HTA VBscript MapIP Printing

    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

      My System SpecsSystem Spec

  2. #2


    Tom Lavedas Guest

    Re: HTA VBscript MapIP Printing

    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

      My System SpecsSystem Spec

HTA VBscript MapIP Printing problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
are VBscript on Windows server 2003 and VBscript on WS2008 compatible? Francois Lafont VB Script 9 26 Apr 2010
Can a vbscript identify the program/process that called a vbscript MarceepooNu VB Script 15 16 Mar 2010
printing a file created by the windows printing dialog (print to f jho PowerShell 3 18 Jun 2009
Where is VBscript now? Brent Morehouse VB Script 2 12 Dec 2008
How to do No hang up VBScript (nohup for VBScript) gimme_this_gimme_that VB Script 3 28 Oct 2008