Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing on Server from .dll 1

Status
Not open for further replies.

btt423

Programmer
Jan 28, 2002
31
US
I am developing a print engine in an ActiveX dll that will be instantiated in an asp page. This print engine needs to loop through the Printers collection of the web server, and print to a printer specified by the user. There will be a predefined list of printers for the user to choose from that are accessible by the server. I'm not trying to have the server print to a client's printer. All the printers are accessible by the server itself.

The print engine works fine as a stand alone application, but when used as an ActiveX dll through an asp page, the printers collection is empty.

It seems that a service can not get access to the Printers on the Win 2000 server. Does anybody have any suggestions?

PLEASE HELP!!!

Thanks!
 
Check that the user the IIS server is running under has access to those printers, if they are domain printers probably not, the IIS services uses a local account, you will neeed to use a DLL from MS that allows you to mimick another user user Search the MS web site for "impersonate user" I thnk that's how I found it.
 
spazman, thanks for the reply. I found the information on microsoft's website, but it isn't doing the logon. The code is below, but the LogonUser call returns false everytime.

Code:
Const LOGON32_LOGON_INTERACTIVE = 2
Const LOGON32_PROVIDER_DEFAULT = 0

Public Sub Logon(ByVal strAdminUser As String, ByVal strAdminPassword As String, ByVal strAdminDomain As String)
    Dim lngTokenHandle, lngLogonType, lngLogonProvider As Long
    Dim blnResult As Boolean

    lngLogonType = LOGON32_LOGON_INTERACTIVE
    lngLogonProvider = LOGON32_PROVIDER_DEFAULT

    WriteToLog ("Logging on...")
    blnResult = RevertToSelf()
    blnResult = LogonUser(strAdminUser, strAdminDomain, strAdminPassword, lngLogonType, lngLogonProvider, lngTokenHandle)
    WriteToLog ("LogonUser executed... result = " & blnResult)
    blnResult = ImpersonateLoggedOnUser(lngTokenHandle)
    WriteToLog ("Impersonate executed... result = " & blnResult)
End Sub

Public Sub Logoff()
    Dim blnResult As Boolean

    blnResult = RevertToSelf()
    WriteToLog ("Logoff executed... result = " & blnResult)
End Sub

Public Function PrintTest() As Boolean
    Dim blnFoundPrinter As Boolean
    
    blnFoundPrinter = False
    WriteToLog ("Finding printers...")
    strChosenPrinter = "HP LaserJet 4050 Series PCL"
    'strChosenPrinter = "Win2PDF"
    i = 0
    For Each prnAvailPrinter In Printers
        WriteToLog "Printer Device: " & prnAvailPrinter.DeviceName
        If prnAvailPrinter.DeviceName = strChosenPrinter Then
            Set Printer = Printers(i)
            WriteToLog "Printer found: " & Printer.DeviceName
            blnFoundPrinter = True
            Exit For
        End If
        i = i + 1
    Next
    
    PrintTest = blnFoundPrinter
End Function

Public Sub WriteToLog(strText As String)
    
    Open App.Path & "\peLog.txt" For Append As #1
    Write #1, "[" & Now & "] " + strText
    Close #1
    
End Sub
 
Is this code with in the ASP?

Just in case you've created the DLL and registered it on the server right?

You could test it like this in ASP
Set objLogon = Server.CreateObject("LoginAdmin.ImpersonateUser")
objLogon.Logon "USERNAME" , "PASSWORD", "DOMAIN"
< DO SOMEHTING ONLY A DOMAIN USER CAN DO HERE! >
objLogon.Logoff
Set objLogon = Nothing

Let me know.
 
spazman...

I had just forgotten to give the SYSTEM account &quot;act as part of operating system&quot; priveleges. Once I did that, it all worked fine.

Thanks for your help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top