Kamyar Nazeri
Kamyar Nazeri

Reputation: 26474

Network Connected Printer not available in ASP.Net Application

I have an ASP.Net 4.0 web application running on IIS 7.5, I can get the list of installed printers using System.Drawing.Printing.PrinterSettings.InstalledPrinters command and assign each report in the application to any printer listed above!

There might be some Network Connected Printers on the server all set with full privilege to the application's user account, everything works perfect until the application's user account logs off the windows, at this point System.Drawing.Printing.PrinterSettings.InstalledPrinters returns only local printers, no Network Connected Printers are listed!

I've tried to impersonate the ASP.Net process to the user with access to Network Printers in following ways, yet no success:

In all of the methods above, the WindowsIdentity returns the true username when printing:

System.Security.Principal.WindowsIdentity.GetCurrent().Name

But it looks like that impersonation is not the issue here, the moment the user logs off, all Network Connected Printers are gone!

Does anybody know how to resolve this? Is there any way to access Network Connected Printers even when the user is not logged in?

Upvotes: 5

Views: 8403

Answers (2)

Kamyar Nazeri
Kamyar Nazeri

Reputation: 26474

Network Connected Printers, Shared Folders and Map Drives are only accessible when user logs into the OS, they are barely a shortcut to some network resources, all disconnected and are inaccessible when the corresponding user logs off!

Using System.Printing.PrintServer and the GetPrintQueues method, you can get the collection of print queues that the print server hosts:

PrintServerUNCName is the UNC name of the corresponding server, as in \\MyServerName

var printers = new PrintServer("PrintServerUNCName").GetPrintQueues()
    .Where(t =>
    {
        try { return t.IsShared && !t.IsNotAvailable; }
        catch { return false; }
    })
    .Select(t => t.FullName)
    .ToArray();

Upvotes: 3

Kamran Pervaiz
Kamran Pervaiz

Reputation: 1931

try following links that might help. You have to add printer on your server by name and access the printer using the name rather UNC.

Printing from ASP.NET to a network printer

Upvotes: 0

Related Questions