473,473 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Network Printers and Web Services

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 on the local machine which works fine when using a test windows application on the server and calling the function directly.

However if the test application first calls a Web Service which then calls the function to retrieve a list of prints I only get a small sub-set of printers installed on the machine.

I believe this problem is related to permissions for the user under which the Web Service runs but I am not sure, does anyone have any ideas on this.

Regards,

Bill
Nov 16 '05 #1
5 20517
Mr. Gates,

First off, let me say what an honor it is that you are gracing our
forums with your presence =P

Anyways, it most likely is a permissions issue like you stated. By
default, the service is running under the ASPNET local account. You will
have to change the web.config file for the directory the service is in to
specify the user to run the service under.

Or, you could look at the documentation of the Impersonate method on the
WindowsIdentity class, and see how to impersonate a user for a section of
code (instead of all code in a directory).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bill Gates" <BG****@microsoft.com> wrote in message
news:eK*************@TK2MSFTNGP12.phx.gbl...
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 on the local machine which works fine when using a test
windows application on the server and calling the function directly.

However if the test application first calls a Web Service which then calls
the function to retrieve a list of prints I only get a small sub-set of
printers installed on the machine.

I believe this problem is related to permissions for the user under which
the Web Service runs but I am not sure, does anyone have any ideas on this.

Regards,

Bill
Nov 16 '05 #2
1. You can't use the printer classes from a service (a webservice runs in the context of a windows service)
2. You can't enumerate Printers from a service.
Printer devices are bound to the context of an interactive user, their attributes are strored in the profile (user hive) of the current user (see HKCU).
A web service runs in the context of a non interactive user (ASPNET by default), so there is no specific user profile loaded for webservices or any other service for that matter (aspnet has no user profile).

If printing is required from a service (but you shouldn't), you have to send the request to another service (or better a COM+ server application - see System.EnterpriseServices)
This service as to create a logon session for a user by calling LogonUser() (Win32 API) followed by a call to LoadUserProfile() (Win32 API) and ImpersonateLoggedOnUser() (Win32 API) before printing.
Note that calling LogonUser is not required if the appliaction is a COM+ application that runs with the credentials of an existing interactive user.

Willy.

"Bill Gates" <BG****@microsoft.com> wrote in message news:eK*************@TK2MSFTNGP12.phx.gbl...
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 on the local machine which works fine when using a test windows application on the server and calling the function directly.

However if the test application first calls a Web Service which then calls the function to retrieve a list of prints I only get a small sub-set of printers installed on the machine.

I believe this problem is related to permissions for the user under which the Web Service runs but I am not sure, does anyone have any ideas on this.

Regards,

Bill
Nov 16 '05 #3
Thanks for the responses they have been very helpful, however still having a little problem as outlined below...

I have taken the code from http://www.codeproject.com/csharp/cpimpersonation1.asp which is used to impersonate a user and implemented this in my project however i am still unable to print through a web service.

The code that I am using to try to print a report is...
--------------------------------------------------------------------------------

private System.Security.Principal.WindowsImpersonationCont ext newUser;

newUser = ImpersonateUser("username", "domain", "password"); // where ImpersonateUser is taken from the CodeProject source

// New User

string sNewUser = System.Security.Principal.WindowsIdentity.GetCurre nt().Name; // Can use this to check the current user
// Run Print

PalletLabel pl = new PalletLabel(); // Crystal Report called PalletLabel.rpt

pl.PrintOptions.PrinterName = [PrinterName]; // PrinterName is the UNC path of the printer (ie \\MyServer\MyPrinter)

pl.PrintToPrinter(1,true,1,1); // Print the damn thing
--------------------------------------------------------------------------------
When I call the web service and pass a printer i get the following error message

Error in File C:\DOCUME~1\dotNET\ASPNET\LOCALS~1\Temp\temp_bd4f3 ceb-6c6e-41b7-bbad-b938cfee7d62.rpt:
Request cancelled by the user.
the code fails at the line "pl.PrintToPrinter(1,true,1,1); // Print the damn thing"

Does anyone have any ideas about this???
If you want I could post a small app with my code in if you think that will help.

Regards

Bill

"Bill Gates" <BG****@microsoft.com> wrote in message news:eK*************@TK2MSFTNGP12.phx.gbl...
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 on the local machine which works fine when using a test windows application on the server and calling the function directly.

However if the test application first calls a Web Service which then calls the function to retrieve a list of prints I only get a small sub-set of printers installed on the machine.

I believe this problem is related to permissions for the user under which the Web Service runs but I am not sure, does anyone have any ideas on this.

Regards,

Bill
Nov 16 '05 #4
"Bill Gates" <BG****@microsoft.com> wrote in message news:uq**************@TK2MSFTNGP14.phx.gbl...
Thanks for the responses they have been very helpful, however still having a little problem as outlined below...

I have taken the code from http://www.codeproject.com/csharp/cpimpersonation1.asp which is used to impersonate a user and implemented this in my project however i am still unable to print through a web service.

The code that I am using to try to print a report is...
------------------------------------------------------------------------------

private System.Security.Principal.WindowsImpersonationCont ext newUser;

newUser = ImpersonateUser("username", "domain", "password"); // where ImpersonateUser is taken from the CodeProject source

// New User

string sNewUser = System.Security.Principal.WindowsIdentity.GetCurre nt().Name; // Can use this to check the current user
// Run Print

PalletLabel pl = new PalletLabel(); // Crystal Report called PalletLabel.rpt

pl.PrintOptions.PrinterName = [PrinterName]; // PrinterName is the UNC path of the printer (ie \\MyServer\MyPrinter)

pl.PrintToPrinter(1,true,1,1); // Print the damn thing
------------------------------------------------------------------------------
When I call the web service and pass a printer i get the following error message

Error in File C:\DOCUME~1\dotNET\ASPNET\LOCALS~1\Temp\temp_bd4f3 ceb-6c6e-41b7-bbad-b938cfee7d62.rpt:
Request cancelled by the user.
the code fails at the line "pl.PrintToPrinter(1,true,1,1); // Print the damn thing"

Does anyone have any ideas about this???
If you want I could post a small app with my code in if you think that will help.
Now you only have created a new logon session, but a few questions remain:

- Was it successful? I mean how do you know it succeeded? What action is taken when it fails?
- Does the impersonating account has access to the remote printer share?
- What if the CR needs access to the HKCU of the impersonating user? (Note that it's hive is not loaded, you didn't load the users profile like I told you)
- What if there's a spooler/printer error message "displayed" when/before printing? Note that server side this message is not visible, and even if it was, who's gonna take the corrective action?
Willy.

Nov 16 '05 #5
odin
1 New Member
Please note that the main problem is security, the application runs as ASPNET account on the OS, and that resticts it from process other things properly.
you can easily change that by impersonating , there are various options for that, i used the web config like that
<configuration>
<system.web>
<identity impersonate="true" userName="user" password="password" />


the user name of course , has to have permissions for that printer,
you can also do it by pasting this into the machine.config, but that will affect all your web applications.

that or search for code for dynamically doing that.
worked for me, probobly will work for you
Apr 26 '06 #6

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

Similar topics

3
by: Matt Chan | last post by:
Hi, I am trying to create a python script to install a set of network printers. I have had success using an os.popen statement, using rundll32 and printui.dll. This takes way too long. Can someone...
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. ...
0
by: Francisco Araujo | last post by:
I have been trying to change printer settings thru SetPrinter API and it works successfully for local printers, but with network printers i don't get neither an error message or anything else. ...
4
by: Phil Galey | last post by:
In VB.NET, Printing.PrinterSettings.InstalledPrinters enumerates only printers connected to the current computer. How can you enumerate network printers?
1
by: Phil Galey | last post by:
Is there any way of enumerating all printers, including network printers in VB.NET? printing.PrinterSettings.InstalledPrinters only enumerates printers attached to the local workstation. ...
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...
2
by: Tessa | last post by:
Hi, We have a .net web application, and are trying to use PrinterSettings.InstalledPrinters to list the printers installed on the webserver. (Windows 2003 server R2, IIS 6, .net framework 2.0.)...
3
by: AricC | last post by:
Occasionally users on my domain lose their network printers. Has anyone heard or seen this? If the user logs out and logs back in the policies push out the correct permissions and they will get...
2
by: calan_svc | last post by:
I have a dll I wrote in VB6. Basically, it can list all the printers it finds as well as print to a selected printer. I created a test app in VB6, added the dll as a reference, and added the...
5
maxamis4
by: maxamis4 | last post by:
Hello folks, What I want to do is scan my subnet for all network printers and return their IP address, serial number, make and model. Same concept as WMI but for network printers. How can this...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
1
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...
0
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,...
1
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.