L
lmttag
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.InstalledPrinters.Count; i++)
{
string installedPrinters =
System.Drawing.Printing.PrinterSettings.InstalledPrinters;
Response.Write("Printer Name: " + installedPrinters);
Response.Write("<br />");
}
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.InstalledPrinters.Count; i++)
{
string installedPrinters =
System.Drawing.Printing.PrinterSettings.InstalledPrinters;
Response.Write("Printer Name: " + installedPrinters);
Response.Write("<br />");
}