Jordan Trajkov

Jordan Trajkov

  • 1.2k
  • 163
  • 9.9k

Access is denied to the network printers for ASP.NET App

Sep 26 2019 11:41 PM
I have instaled asp.net application on a server. I want to display network printers in a dropdown and i use this codes to achive that goal:
 
  1. Protected Overrides Sub LoadPrinters()  
  2.         Dim permison As New PrintingPermission(PrintingPermissionLevel.AllPrinting)  
  3.   
  4.         If Not IsPostBack Then  
  5.             Dim strPrinter As String  
  6.             Dim li As ListItem  
  7.             dlPrinters.Items.Clear()  
  8.             dlPrinters.Items.Add(New ListItem("Select Printer"""))  
  9.   
  10.             For Each strPrinter In System.Drawing.Printing.PrinterSettings.InstalledPrinters  
  11.                 dlPrinters.Items.Add(strPrinter)  
  12.             Next  
  13.         End If  
Also i try this code:
 
  1. Private Sub PrinterList()  
  2.    
  3.   
  4.     ' USING WMI. (Windows Management Instrumentation)  
  5.     Dim objMS As System.Management.ManagementScope = _  
  6.         New System.Management.ManagementScope(ManagementPath.DefaultPath)  
  7.     objMS.Connect()  
  8.   
  9.     Dim objQuery As SelectQuery = New SelectQuery("SELECT * FROM Win32_Printer")  
  10.     Dim objMOS As ManagementObjectSearcher = New ManagementObjectSearcher(objMS, objQuery)  
  11.     Dim objMOC As System.Management.ManagementObjectCollection = objMOS.Get()  
  12.   
  13.     dlPrinters.Items.Clear()  
  14.     dlPrinters.Items.Add(New ListItem("Select Printer"""))  
  15.   
  16.     For Each Printers As ManagementObject In objMOC  
  17.         If CBool(Printers("Local")) Then                        ' LOCAL PRINTERS.  
  18.             dlPrinters.Items.Add(Printers("Name"))  
  19.         End If  
  20.         If CBool(Printers("Network")) Then                      ' ALL NETWORK PRINTERS.  
  21.             dlPrinters.Items.Add(Printers("Name"))  
  22.         End If  
  23.     Next Printers  
  24. End Sub  
In both scenarios i cannot see network printers in the dropdown list and if i use second code i can see error: Access is denied.
 
My application is using impersonate account with full permision to the network and printers. What else can make the problems? 
 
 

Answers (2)