on 03-24-2016 2:25 PM
I have created a window service that will process reports and then call the PrintToPrinter to print them on a specified printer. The service prints the reports if the service runs on a local machine but it doesn't print the reports when it runs on a window virtual machine. FYI, It doesn't throw any exceptions. I've been searching for reasons/solutions but haven't found anything. Please advise. Below is the code that I use.
public void PrintReports(string printer)
{
try
{
GetReportDocument().PrintOptions.PrinterName = printer;
GetReportDocument().PrintToPrinter(new PrinterSettings { PrinterName = printer }, new PageSettings(), false);
}
catch(Exception e)
{
................
}
}
I had some problems with this myself. As Don said, my issue had to do with the system account not knowing about the printers. I handled it at runtime by writing a piece of code that copied a registry tree hierarchy then invoked it as follows. Params are from and to.
// Network
copyRegistryTree(HKEY_CURRENT_USER, "Printers\\Connections",
HKEY_USERS, ".Default\\Printers\\Connections");
// Local
copyRegistryTree(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Devices",
HKEY_USERS, ".Default\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Devices");
copyRegistryTree(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\PrinterPorts",
HKEY_USERS, ".Default\\Software\\Microsoft\\Windows NT\\CurrentVersion\\PrinterPorts");
copyRegistryTree(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
HKEY_USERS, ".Default\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What OS is the web service running on? On newer versions of Windows Server, you MUST have the printer defined and the drivers installed on the server in order to be able to print to it. So, this may not be a Crystal issue, it may be an OS issue.
-Dell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What type of account is being used to run the webservice? If it's a local (to the machine) account, then the webservice may not have access to any network printers. Try running it under an account that has access to the network (you can use your own credentials for testing) and see whether that helps.
-Dell
Hi Cody,
Dell is correct, You must install the printers locally, RDC causes huge delays when printing if it uses the (redirected 2), also labelled by MS as "Easy Print".
For app's running as a service it needs to get the printer info from the Admin/System account.
If you run your service under your local user account I suspect it would work.
To add your User Printers to the System account see the MS KBA on how to:
//For printers exposed to System account as per MS Kbase
http://support.microsoft.com/default.aspx?scid=kb;en-us;184291
Be aware if you make changes to the printers this location must also be manually updated with the changes.
And usual warning about modifying the registry manually.
Don
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.