Skip to Content
author's profile photo Former Member
Former Member

PrintToPrinter doesn't work when printing from a windows service in a virtual machine

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)

{

................

}

}

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Apr 08, 2016 at 06:49 PM

    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");

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 24, 2016 at 03:42 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Don Williams Dell Stinnett-Christy

      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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.