REPOST: User add Printers via Web page?

Discussion in 'ASP General' started by Aaron_TekRecycle.com, Jul 23, 2003.

  1. Someone must have done this before?!?

    I have VBS code that will Enumerate all the Printers in the AD and Add the
    Printer Connection to the client... I'm just not a web developer so I need
    some example code or hand-holding on the web integration portion.

    Anyone?
     
    Aaron_TekRecycle.com, Jul 23, 2003
    #1
    1. Advertisements

  2. Aaron_TekRecycle.com

    Tom B Guest

    You'd have to do this in two parts.
    The ASP part would do the enumeration....which should be nearly identical to
    te code you have.
    Then, client side script would install the printer on the client (if the
    user grants permission)

    You've posted this to many newsgroups, why? Most of the groups you selected
    are irrelevant.

    Post your VBS script and I'm sure someone can assist.
     
    Tom B, Jul 23, 2003
    #2
    1. Advertisements

  3. Aaron_TekRecycle.com

    DJL Guest

    Post your vbscript?

     
    DJL, Jul 23, 2003
    #3
  4. Here's the ASP I has so far (commented)...

    ------ printers.asp --------
    <%
    Option Explicit
    Response.Buffer = True
    %>

    <html>
    <head>
    <style>
    body, p, td { font-family:Verdana;font-size:8pt; }
    </style>
    </head>

    <body>


    <%
    EnumADprinters

    %>

    </body>
    </html>

    <%
    ' *************************************************
    ' Enumerate all AD printers
    '
    ' reference:
    ' Microsoft:
    http://eu.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcent
    er/printing/default.asp
    ' *************************************************
    Function EnumADprinters()

    Dim objConnection, objCommand, objRecordSet
    Dim oPrinterName, oServerName

    Const ADS_SCOPE_SUBTREE = 2
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection
    objCommand.CommandText = "Select printerName, serverName from " _
    & " 'LDAP://DC=corp,DC=binghameq,DC=com' where objectClass='printQueue'"
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Timeout") = 30
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    objCommand.Properties("Cache Results") = False
    Set objRecordSet = objCommand.Execute
    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF ' should place data into array - TODO
    Set oPrinterName = objRecordSet.Fields("printerName").Value
    Set oServerName = objRecordSet.Fields("serverName").Value
    'Wscript.Echo "Printer Name: " & oPrinterName & vbcr & "Server Name: "
    & oServerName

    ' NOTE: would be better to put into array and pass array to function to
    build table... not sure how to do this.

    ' Create table to show Printers
    Response.Write "<table align=""center"" border=""1""" & _
    " width=""80%"""
    Response.Write " cellspacing=""0"" cellpadding=""5""" & _
    " bordercolor=""black"">"
    Response.Write vbcrlf
    BuildPrinterTable ' send to function to build rows/columns
    Response.Write "</table>"

    objRecordSet.MoveNext

    Loop

    End Function

    ' *************************************************
    ' Display Printers from Active Directory in table
    ' *************************************************
    Function BuildPrinterTable(oPrinterName,oServerName)

    ' Build Row
    Response.Write "<tr>" & vbcrlf

    ' Build Column
    Response.Write "<td>"
    Response.Write oPrinterName
    Response.Write "</td>"
    Response.Write "<td>"
    Response.Write oServerName
    Response.Write "</td>"
    Response.Write "<td>"
    Response.Write "<FORM NAME=" & oPrinterName &" ACTION=" & MapPrinter() & "
    METHOD=""get"" ><input type=""checkbox"" name=""box"" value=" & oPrinterName
    & "></form>" ' Creates Form for each Printer -- this must execute on the
    CLIENT side
    Response.Write "</td>"

    Response.Write "</tr>" & vbcrlf

    End Function

    ' *************************************************
    ' Map Printers to User Profile
    ' *************************************************
    Function MapPrinter(oServerName,oPrinterName)

    Set strPrinter = "\\" & oServerName &"\" & oPrinterName ' complete
    Printer path and name
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection(strPrinter)
    ' Alternative method (user & pw optional):
    ' WshNetwork.AddPrinterConnection
    "LPT1",strPrinter,FALSE,"Domain\userid","password"
    End Function



    %>
     
    Aaron_TekRecycle.com, Jul 23, 2003
    #4
  5. I need help passing the info from the server side -> web page display ->
    client side

    Here's the .VBS I have so far (commented)...

    ---------- printers.asp -------------

    <%
    Option Explicit
    Response.Buffer = True
    %>

    <html>
    <head>
    <style>
    body, p, td { font-family:Verdana;font-size:8pt; }
    </style>
    </head>

    <body>


    <%
    EnumADprinters

    %>

    </body>
    </html>

    <%
    ' *************************************************
    ' Enumerate all AD printers
    '
    ' reference:
    ' Microsoft:
    http://eu.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcent
    er/printing/default.asp
    ' *************************************************
    Function EnumADprinters()

    Dim objConnection, objCommand, objRecordSet
    Dim oPrinterName, oServerName

    Const ADS_SCOPE_SUBTREE = 2
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection
    objCommand.CommandText = "Select printerName, serverName from " _
    & " 'LDAP://DC=corp,DC=binghameq,DC=com' where objectClass='printQueue'"
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Timeout") = 30
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    objCommand.Properties("Cache Results") = False
    Set objRecordSet = objCommand.Execute
    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF ' should place data into array - TODO
    Set oPrinterName = objRecordSet.Fields("printerName").Value
    Set oServerName = objRecordSet.Fields("serverName").Value
    'Wscript.Echo "Printer Name: " & oPrinterName & vbcr & "Server Name: "
    & oServerName

    ' NOTE: would be better to put into array and pass array to function to
    build table... not sure how to do this.

    ' Create table to show Printers
    Response.Write "<table align=""center"" border=""1""" & _
    " width=""80%"""
    Response.Write " cellspacing=""0"" cellpadding=""5""" & _
    " bordercolor=""black"">"
    Response.Write vbcrlf
    BuildPrinterTable ' send to function to build rows/columns
    Response.Write "</table>"

    objRecordSet.MoveNext

    Loop

    End Function

    ' *************************************************
    ' Display Printers from Active Directory in table
    ' *************************************************
    Function BuildPrinterTable(oPrinterName,oServerName)

    ' Build Row
    Response.Write "<tr>" & vbcrlf

    ' Build Column
    Response.Write "<td>"
    Response.Write oPrinterName
    Response.Write "</td>"
    Response.Write "<td>"
    Response.Write oServerName
    Response.Write "</td>"
    Response.Write "<td>"
    Response.Write "<FORM NAME=" & oPrinterName &" ACTION=" & MapPrinter() & "
    METHOD=""get"" ><input type=""checkbox"" name=""box"" value=" & oPrinterName
    & "></form>" ' Creates Form for each Printer -- this must execute on the
    CLIENT side
    Response.Write "</td>"

    Response.Write "</tr>" & vbcrlf

    End Function

    ' *************************************************
    ' Map Printers to User Profile
    ' *************************************************
    Function MapPrinter(oServerName,oPrinterName)

    Set strPrinter = "\\" & oServerName &"\" & oPrinterName ' complete
    Printer path and name
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection(strPrinter)
    ' Alternative method (user & pw optional):
    ' WshNetwork.AddPrinterConnection
    "LPT1",strPrinter,FALSE,"Domain\userid","password"
    End Function



    %>
     
    Aaron_TekRecycle.com, Jul 23, 2003
    #5
  6. Aaron_TekRecycle.com

    Tom B Guest

    Change your MapPrinter to client side
    <SCRIPT LANGUAGE=VBScript>
    Function MapPrinter....
    </SCRIPT>

    Call the function when the user clicks a button
    <input type=button onClick="MapPrinter 'BobServer','BobPrinter'"
    Value="\\BobServer\BobPrinter">
     
    Tom B, Jul 24, 2003
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.