Click here to Skip to main content
15,889,556 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:


Protected Overrides Sub LoadPrinters()
Dim permison As New PrintingPermission(PrintingPermissionLevel.AllPrinting)

If Not IsPostBack Then
Dim strPrinter As String
Dim li As ListItem
dlPrinters.Items.Clear()
dlPrinters.Items.Add(New ListItem("Select Printer", ""))

For Each strPrinter In System.Drawing.Printing.PrinterSettings.InstalledPrinters
dlPrinters.Items.Add(strPrinter)
Next
End If


Also i try this code:



Private Sub PrinterList()  
   
  
    ' USING WMI. (Windows Management Instrumentation)  
    Dim objMS As System.Management.ManagementScope = _  
        New System.Management.ManagementScope(ManagementPath.DefaultPath)  
    objMS.Connect()  
  
    Dim objQuery As SelectQuery = New SelectQuery("SELECT * FROM Win32_Printer")  
    Dim objMOS As ManagementObjectSearcher = New ManagementObjectSearcher(objMS, objQuery)  
    Dim objMOC As System.Management.ManagementObjectCollection = objMOS.Get()  
  
    dlPrinters.Items.Clear()  
    dlPrinters.Items.Add(New ListItem("Select Printer", ""))  
  
    For Each Printers As ManagementObject In objMOC  
        If CBool(Printers("Local")) Then                        ' LOCAL PRINTERS.  
            dlPrinters.Items.Add(Printers("Name"))  
        End If  
        If CBool(Printers("Network")) Then                      ' ALL NETWORK PRINTERS.  
            dlPrinters.Items.Add(Printers("Name"))  
        End If  
    Next Printers  
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? 


What I have tried:

I try many examples how to read the printers but it is not working
Posted
Updated 30-Sep-19 1:55am
Comments
F-ES Sitecore 30-Sep-19 4:32am    
If your app has full access to network and printers then you wouldn't be getting an access denied error, so maybe your app doesn't have the permissions you think it does?
JordanTrajkov 30-Sep-19 21:07pm    
I create new user with full permisions and add it as a impersonate user in web config. if i run my app with localhost domain i can see the printers on the network. If i run it with ip address of the machine it gives error access denied.
Maybe i'm missing to set a permisions somwhere?

1 solution

The (service?) account unhder which your web app runs does not have access to the printers. Bigger question - Why would you want a web app to access printers? That seems to be ripe for abuse.
 
Share this answer
 
Comments
JordanTrajkov 30-Sep-19 21:08pm    
I create new user with full permisions and add it as a impersonate user in web config. if i run my app with localhost domain i can see the printers on the network. If i run it with ip address of the machine it gives error access denied.

We need this because we have a online archive application for documents which have to be printed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900