Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Network printing

Network printing

Scheduled Pinned Locked Moved ASP.NET
sysadminhelpcsharpvisual-studiowindows-admin
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Armandt__
    wrote on last edited by
    #1

    Hi everyone I have searched the whole day long now and cant seen to find, maybe searching in the wrong places:confused: If someone could please help me I have a aspx vb project using crystal reports, now what I want to do is , when the user hits the print button the report should print to a printer shared on a computer connected to the network. Now this is working when I run the app in visual studio but when its published to the iis it gives me a "access denied" error when i set the printer as \\pcIP\printername , or when i view the printer queue it says, "error - printing" when i set the printer as a normal printer on the server giving it a new port looking at the same place as before this is how i do it create a report doc -> rpt rpt.PrintOptions.PrinterName = "\\IP\printer" rpt.PrintToPrinter(1, False, 0, 0) any help would be great

    A 1 Reply Last reply
    0
    • A Armandt__

      Hi everyone I have searched the whole day long now and cant seen to find, maybe searching in the wrong places:confused: If someone could please help me I have a aspx vb project using crystal reports, now what I want to do is , when the user hits the print button the report should print to a printer shared on a computer connected to the network. Now this is working when I run the app in visual studio but when its published to the iis it gives me a "access denied" error when i set the printer as \\pcIP\printername , or when i view the printer queue it says, "error - printing" when i set the printer as a normal printer on the server giving it a new port looking at the same place as before this is how i do it create a report doc -> rpt rpt.PrintOptions.PrinterName = "\\IP\printer" rpt.PrintToPrinter(1, False, 0, 0) any help would be great

      A Offline
      A Offline
      Armandt__
      wrote on last edited by
      #2

      Ok so no reply from anyone, so I'll leave what I got When using network resources the asp.net "user" doesn’t have the required rights. So , what you need to do is impersonate a user on the sever having the rights the access the network . Create a class, call it whatever you want, I’ll call this one impersonation and add the following: Some of the imports won’t be needed

      Imports Microsoft.VisualBasic
      Imports System.Web.Security
      Imports System.Security.Principal
      Imports System.Runtime.InteropServices
      Imports System.Threading
      Imports System.Configuration
      Imports SR = System.Reflection
      Imports System.Text
      Imports System.Web.UI.WebControls

      Public Class Impersonation
      Private Const LOGON32_PROVIDER_DEFAULT As Integer = 0
      Private Const LOGON32_LOGON_INTERACTIVE As Integer = 2
      Private Const LOGON32_LOGON_NETWORK As Integer = 3
      Private Const LOGON32_LOGON_BATCH As Integer = 4
      Private Const LOGON32_LOGON_SERVICE As Integer = 5
      Private Const LOGON32_LOGON_UNLOCK As Integer = 7
      Private Const LOGON32_LOGON_NETWORK_CLEARTEXT As Integer = 8
      Private Const LOGON32_LOGON_NEW_CREDENTIALS As Integer = 9

      Private Shared ImpersonationContext As WindowsImpersonationContext
      
      Declare Function LogonUserA Lib "advapi32.dll" ( \_
                              ByVal lpszUsername As String, \_
                              ByVal lpszDomain As String, \_
                              ByVal lpszPassword As String, \_
                              ByVal dwLogonType As Integer, \_
                              ByVal dwLogonProvider As Integer, \_
                              ByRef phToken As IntPtr) As Integer
      
      Declare Auto Function DuplicateToken Lib "advapi32.dll" ( \_
                              ByVal ExistingTokenHandle As IntPtr, \_
                              ByVal ImpersonationLevel As Integer, \_
                              ByRef DuplicateTokenHandle As IntPtr) As Integer
      Declare Auto Function RevertToSelf Lib "advapi32.dll" () As Long
      Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal handle As IntPtr) As Long
      
      Public Shared Function ImpersonateValidUser(ByVal strUserName As String, \_
                     ByVal strDomain As String, ByVal strPassword As String) As Boolean
          Dim token As IntPtr = IntPtr.Zero
          Dim tokenDuplicate As IntPtr = IntPtr.Zero
          Dim tempWindowsIdentity As WindowsIdentity
      
          ImpersonateValidUser = False
      
          If RevertToSelf() <> 0 Then
              If LogonUserA(st
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups