HELP : URGENT : How to get the list of printers on the web server?

G

gnusmsa

ASP.NET 2.0 (C#) application
Using Windows authentication and impersonation
Windows Server 2003 (IIS6)
Server is a member server on a domain
Logged into server as a domain user that is in the local Administrators
group on the server
Workstation is on the same domain
Logged into the workstation as the same domain user, which is also in the
local Administrators group on the workstation



I'm having what seems like a strange problem. I have an ASP.NET 2.0 (C#)
application that is running on my Windows Server 2003 web server. In this
application, I have an .aspx page that tries to get the list of printers on
the web server (using code-behind).

When I run the application using IE on the server, it works fine and I get a
list of the printers on the server. However, when I run the application
from the workstation using IE (simply pointing the URL to the server), I
cannot get the list of printers.

I'm trying to use WMI (2 kind of different ways) to get the list of printers
on the server. Below is some of the code snippets from my project.


Web.config
<system.web>
<authentication mode="Windows"/>
<identity impersonate="true"/>
...
</system.web>


..aspx page
(works from the server but not any workstation)
using (System.Management.ManagementClass exportedShares = new
System.Management.ManagementClass("Win32_Printer"))
{
System.Management.ManagementObjectCollection shares =
exportedShares.GetInstances();

foreach (System.Management.ManagementObject share in shares)
{
Response.Write("Name: " + mo["Name"].ToString());
Response.Write("<br />");
Response.Write("Default: " + mo["Default"].ToString());
Response.Write("<br />");
Response.Write("Description: " +
share["Description"].ToString());
Response.Write("<br />");
Response.Write("Local: " + share["Local"].ToString());
Response.Write("<br />");
Response.Write("Network: " + share["Network"].ToString());
Response.Write("<br />");
Response.Write("Shared: " + share["Shared"].ToString());
Response.Write("<br />");
Response.Write("Location: " + share["Location"].ToString());
Response.Write("<br />");
Response.Write("ServerName: " +
share["ServerName"].ToString());
Response.Write("<br />");
Response.Write("ShareName: " +
share["ShareName"].ToString());
Response.Write("<br />");
}
}


..aspx page (try #2)
(works from the server but not any workstation)
System.Management.ConnectionOptions co = new
System.Management.ConnectionOptions();
co.Authentication = System.Management.AuthenticationLevel.Default;
co.Impersonation = System.Management.ImpersonationLevel.Impersonate;
System.Management.ManagementScope ms = new
System.Management.ManagementScope("\\\\" + computer, co);
System.Management.ObjectQuery oq = new
System.Management.ObjectQuery("SELECT * FROM Win32_Printer");
System.Management.ManagementObjectSearcher mos = new
System.Management.ManagementObjectSearcher(ms, oq);
System.Management.ManagementObjectCollection moc = mos.Get();

foreach (System.Management.ManagementObject mo in moc)
{
Response.Write("Name: " + mo["Name"].ToString());
Response.Write("<br />");
Response.Write("Default: " + mo["Default"].ToString());
Response.Write("<br />");
Response.Write("Description: " + mo["Description"].ToString());
Response.Write("<br />");
Response.Write("Local: " + mo["Local"].ToString());
Response.Write("<br />");
Response.Write("Network: " + mo["Network"].ToString());
Response.Write("<br />");
Response.Write("Shared: " + mo["Shared"].ToString());
Response.Write("<br />");
Response.Write("Location: " + mo["Location"].ToString());
Response.Write("<br />");
Response.Write("ServerName: " + mo["ServerName"].ToString());
Response.Write("<br />");
Response.Write("ShareName: " + mo["ShareName"].ToString());
Response.Write("<br />");
}



Can some one please help me understand what's going on and how to resolve
this problem?

Thanks!
 
R

r2thej151

Are you trying to iterate all availalbe network printers or just
installed printers? If the later, have you tried
System.Drawing.Printing.PrinterSettings.InstalledPrinters?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top