473,325 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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

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
1 3551
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Simon Thompson | last post by:
Hi, I have a VB6 ActiveX DLL that we use for printing. It iterates through the printers collection to set the printer to the one the user requested. This is called from ASP (VB Script) pages,...
4
by: Brett Mostert | last post by:
Hi, I need to be able to Enumerate through Printer Drivers, ports, printers and so fourth. And even add printers, ports, and drivers and setup printers. Sofar i can do all of the following...
0
by: Dexter | last post by:
Hello all, I need to list in a dropdownlist, all network printers. I have a server with 6 printers, and I need to do a direct print at printer that the user to select in a dropdownlist. ...
5
by: Rik Hemsley | last post by:
Hi, My ASP.NET application (running on IIS) doesn't see any of the printers installed on its server. I'd like it to be able to see, and print to, all printers. Is there a way to give the...
2
by: J | last post by:
Hello, I'm using the following snippet of code to try and get a list of all the printers installed on this machine. I have installed some network printers on this machine and they just won't...
1
by: gnusmsa | last post by:
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...
5
by: lmttag | last post by:
ASP.NET 2.0 (C#) application Intranet application (not on the Internet) Using Windows authentication and impersonation Windows Server 2003 (IIS6) Server is a member server on a domain Logged...
2
by: smartic | last post by:
i'm having three lists when i select from any one the others be visible by hierarchy but it takes to long to write my code is there is another away to write this code like XML that is my javascript...
0
by: drewgy | last post by:
Can anyone tell me how to get a list of full UNC paths for all printers on a network? I have tried using WMI but the following code only gives me a list of local printers, and doesn't give me the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.