473,722 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>
<authenticati on mode="Windows"/>
<identity impersonate="tr ue"/>
...
</system.web>
..aspx page
(works from the server but not any workstation)
using (System.Managem ent.ManagementC lass exportedShares = new
System.Manageme nt.ManagementCl ass("Win32_Prin ter"))
{
System.Manageme nt.ManagementOb jectCollection shares =
exportedShares. GetInstances();

foreach (System.Managem ent.ManagementO bject share in shares)
{
Response.Write( "Name: " + mo["Name"].ToString());
Response.Write( "<br />");
Response.Write( "Default: " + mo["Default"].ToString());
Response.Write( "<br />");
Response.Write( "Descriptio n: " +
share["Descriptio n"].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.Manageme nt.ConnectionOp tions co = new
System.Manageme nt.ConnectionOp tions();
co.Authenticati on = System.Manageme nt.Authenticati onLevel.Default ;
co.Impersonatio n = System.Manageme nt.Impersonatio nLevel.Imperson ate;
System.Manageme nt.ManagementSc ope ms = new
System.Manageme nt.ManagementSc ope("\\\\" + computer, co);
System.Manageme nt.ObjectQuery oq = new
System.Manageme nt.ObjectQuery( "SELECT * FROM Win32_Printer") ;
System.Manageme nt.ManagementOb jectSearcher mos = new
System.Manageme nt.ManagementOb jectSearcher(ms , oq);
System.Manageme nt.ManagementOb jectCollection moc = mos.Get();

foreach (System.Managem ent.ManagementO bject mo in moc)
{
Response.Write( "Name: " + mo["Name"].ToString());
Response.Write( "<br />");
Response.Write( "Default: " + mo["Default"].ToString());
Response.Write( "<br />");
Response.Write( "Descriptio n: " + mo["Descriptio n"].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 3591
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
1579
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, and from a VB Web Class application. The problem is, sometimes the printers collection is empty, so it fails to print. The COM+ package is configured to run as a known user. This user has printers configured. If we logon to the Web Server as the...
4
6996
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 except anything to do with drivers. I have added a reference to the PRNADMIN.DLL from MS Windows 2003 Tool Kit into my project to do all of the above, but when i try to enumerate printers i received the following error....
0
1393
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. Somebody have some idea about this? Dexter
5
2055
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 ASP.NET user this kind of access? Apologies if this is an IIS newbie question!
2
4803
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 show up! This is in a webservice method, if that makes any differance. Also, when I change the query to "Select * from Win32_Process" I do return many processes, any ideas to what might be causing this?
1
1111
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 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
5
6682
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 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 a domain user, which is also in the local Administrators group on the server and workstation
2
1728
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 code ex: function ChangeCategory(ForWhat){ switch(ForWhat.selectedIndex){ case 0: //if he selected noothing document.getElementById("Type").innerHTML=""; document.getElementById("CType").innerHTML="";...
0
1363
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 fully qualified paths. private void GetNetworkPrinters() { try { string strQuery = "SELECT * FROM Win32_Printer";
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.