User add Printers via Web page?

  • Thread starter Aaron_TekRecycle.com
  • Start date
A

Aaron_TekRecycle.com

Does anyone know of an ASP page that will query the AD and list all the
printers so the users can "click to add" printer mappings to their profile?


thanks!
Aaron

--
Tek Recycle
www.TekRecycle.com
* your source for the best prices on Sony InfoLithium batteries,
camera/camcorder accessories, Home electronics and
small appliances, and tools!
 
A

Aaron_TekRecycle.com

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?
 
D

DJL

Post your vbscript?

Aaron_TekRecycle.com said:
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?
 
A

Aaron_TekRecycle.com

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



%>
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top