473,232 Members | 1,538 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,232 software developers and data experts.

HELP: Cannot get network and local printers on the web server.

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
From the workstation, I need to get the list of printers installed on the
server (both network and local printers). Using IE on the server, I can see
all the installed printers. However, from the workstation, also using IE, I
cannot see/get the list of printers installed on the server.

The ASP.NET application, has an .aspx page that tries to get the list of
printers on the web server (using code-behind). Again, 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 on the server), I cannot get
the list of printers.

Below is some of the code snippets from my project. I've tried 3 different
ways, but none work. Any suggestions?
Web.config
<system.web>
<authentication mode="Windows"/>
<identity impersonate="true"/>
...
</system.web>
..aspx.cs attempt 1
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: " + share["Name"].ToString());
Response.Write("<br />");
Response.Write("Default: " +
share["Default"].ToString());
Response.Write("<br />");

if (share["Description"] == null)
{
Response.Write("Description: ");
Response.Write("<br />");
}
else
{
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 />");

if (share["Location"] == null)
{
Response.Write("Location: ");
Response.Write("<br />");
}
else
{
Response.Write("Location: " +
share["Location"].ToString());
Response.Write("<br />");
}

if (share["ServerName"] == null)
{
Response.Write("ServerName: ");
Response.Write("<br />");
}
else
{
Response.Write("ServerName: " +
share["ServerName"].ToString());
Response.Write("<br />");
}

if (share["ShareName"] == null)
{
Response.Write("ShareName: ");
Response.Write("<br />");
}
else
{
Response.Write("ShareName: " +
share["ShareName"].ToString());
Response.Write("<br />");
}
}
}
..aspx.cs attempt 2
string computer = System.Environment.MachineName;
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 />");

if (mo["Description"] == null)
{
Response.Write("Description: ");
Response.Write("<br />");
}
else
{
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 />");

if (mo["Location"] == null)
{
Response.Write("Location: ");
Response.Write("<br />");
}
else
{
Response.Write("Location: " +
mo["Location"].ToString());
Response.Write("<br />");
}

if (mo["ServerName"] == null)
{
Response.Write("ServerName: ");
Response.Write("<br />");
}
else
{
Response.Write("ServerName: " +
mo["ServerName"].ToString());
Response.Write("<br />");
}

if (mo["ShareName"] == null)
{
Response.Write("ShareName: ");
Response.Write("<br />");
}
else
{
Response.Write("ShareName: " +
mo["ShareName"].ToString());
Response.Write("<br />");
}
}
..aspx.cs attempt 3
for (int i = 0; i <
System.Drawing.Printing.PrinterSettings.InstalledP rinters.Count; i++)
{
string installedPrinters =
System.Drawing.Printing.PrinterSettings.InstalledP rinters[i];
Response.Write("Printer Name: " + installedPrinters);
Response.Write("<br />");
}

Apr 20 '07 #1
5 6634
Hi lmttag,

Regarding on the query printers behavior in ASP.NET web application, I have
performed some local test according to your description and did find the
symptom. And based on my research and test, here is my understanding and
suggest on this problem:

** When you configure IIS to use intergrated windows authentication(disable
anonymous access), the client security token forwarded from IIS(to ASP.NET)
is a network logon session's token. Therefore, when you use <identity
impersonate="true" / to impersonate against this network logon token, it
won't see any printers that you can see under interactive logon user
session.

** The reason why it works when you visit the page locally on the server
machine is that when you visit the page locally on the server, IE will use
your local interactive logon session's token rather than establish a new
network logon session against IIS.

I'm not sure whether you'll want to query printers for different client
users or just want to let client users get a list of all the available
printers on a server. Is it possible for your to use a fixed account for
query printers? So far, if you want to get all the printers, you need to
create an interactive logon session and impersonate undere that session.
Here is the knowledge base article that has demonstrate the code of
programmatically create an interactive logon session and impersonate in
ASP.NET:

#How to implement impersonation in an ASP.NET application
http://support.microsoft.com/kb/306158

Also, for testing , you can use <identity impersonate="true"
userName="username" password="password" /to specify the clear text
credential of a fixed account, this can also make the ASP.NET application
impersonate under a fixed interactive logon session that can see all the
printers available to that account. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.





Apr 23 '07 #2
Hi Imttag,

How are you doing on this issue? Does the information and suggestion in my
last reply helps you a little? If there is anything else you wonder or we
can help, please don't hesitate to post here.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 25 '07 #3
Hello Steven,
Thank you for the follow-up. I, unfortunately, have not been able to figure
out/fix my issue. I looked at the information you provided and tried a
couple things. But no progress yet.

From a workstation/client that is using the ASP.NET intranet app., I just
need to see a list of available printers on the server (both local printers
and any network printers). I don't need to actually send a print job or
anything like that. I simply need a list of printers, then one of the
printers in the list gets picked and I save the printer name to a database
table. It seems pretty easy in theory.

And, since we sell this ASP.NET intranet app. to our customers, I cannot
hard-code a user name and password in the web.config or in any impersonation
code. This is because the end-user customers may have different users and
passwords, and we can't force them to create some user for this purpose. If
that makes sense...

So, I'm still kind of at a loss on how to get this to work. I'm sure it's
some sort of security, permissions, etc. issue that I don't know how to get
around yet.

Any other thoughts?
Thanks!
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:0C******************@TK2MSFTNGHUB02.phx.gbl.. .
Hi Imttag,

How are you doing on this issue? Does the information and suggestion in my
last reply helps you a little? If there is anything else you wonder or we
can help, please don't hesitate to post here.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.
>

Apr 26 '07 #4
Thanks for your reply Imttag,

For integrated windows authenticated user, since the security token is not
of a interactive logon, it may not get all the printer info(like a
interactive logon user). I think one possible solution would be configure
IIS to use "basic" authentication since this will require client-side to
input clear text username/password credential, and we can also configure
IIS to use interactive logon for basic authenticated user:

#Basic Authentication (IIS 6.0)
http://www.microsoft.com/technet/pro.../Library/IIS/c
f438d2c-f9c7-4351-bf56-d2ab950d7d6e.mspx?mfr=true

is using basic authentiation an possible approach for your scenario?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

May 1 '07 #5
Hi Imttag,

Any progress on this issue? If there is still anything we can help, please
feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

May 3 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bill Gates | last post by:
Hello, I am having a little trouble accessing a list of printers on our Network through a web service... I am using the PrinterSettings.InstalledPrinters to access a list of printers installed...
1
by: Homa | last post by:
I have a web service that want to print something to a printer connected on another computer in the network. And that printer happens to be a non-plug and play printer (It's a thermal printer). ...
1
by: Maileen | last post by:
Hi, We have a little problem in 1 of our ASP page :( on this page, we can add new printers (local or network) and to print a report on a selected (by default) printer. We we do the test on a...
13
by: Siegfried Heintze | last post by:
I refered the engineer at my hosting service to http://support.microsoft.com/default.aspx?scid=kb;en-us;825738 where he tried to follow the directions there. He said there was no such file:...
11
by: pamelafluente | last post by:
I am doing my own PrintDialog, and have placed there a combo with the printer names, as in the PrintDialog provided by VB.NET. Here is the question: how do I open the native windows printer...
56
by: peng | last post by:
Hi, I am development a project using C#.Net. Inside application, it needs to print labels on different Zebra label printers on the network. I used a shell script, but it only worked on the...
0
by: prakashkoshti | last post by:
I have an applicaiton developed in ASP.Net. I have installed network printers on my machine. (Installed printers include both USB and COM) When I try to print from other interactive applications...
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...
2
by: jawaid alam | last post by:
Hi all forum Member, I am facing very tropical type of problem. I devoloped a intranet web project. I want to print crystal report by selecting network printer. I accessed all network printer...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
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...

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.