By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,974 Members | 1,834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,974 IT Pros & Developers. It's quick & easy.

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

P: n/a
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!

Aug 18 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I had a similar problem accessing server printers from MTS in the days of
NT4. I have no idea whether this information is still valid, but at that
time the problem turned out to be that the user hive for the identity used by
the package was not loaded automatically. Our work around was to start a
service using the identity. That caused the user hive to be loaded.

You could try specifying a domain account for the identity in your
web.config (or altering the processModel element in the server
machine.config), log in interactively on the server as that account and
verify that the printers are defined, and start a service (e.g. clipboard)
using the identity to ensure that the hive is loaded.

Note that the user hive is cached. Once it is loaded for a given user, it
remains in memory until the server is rebooted. This can lead to confusing
behaviour where things that worked yesterday refuse to work today.

http://support.microsoft.com/kb/184291/en-us

http://support.microsoft.com/kb/202785/en-us

Gavin
Aug 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.