Printing from a Service

Environment: Windows NT 4

The Problem

Have you ever attempted to print from a Windows NT Service?

Some time ago my colleagues and I wrote a TCP/IP server to collect data, analyze it and then print exceptions. Obviously, printing is usually a very simple and typical task for any software engineer.

When I finished developing this application, I then converted it to a Windows NT service. Everything seemed to work well with one exception. The application wouldn't print anything!

With my heart in my hands, I then began the arduous task of walking the registry and searching for a solution. Finally, I found it after a few days.

The solution

  • Locate the following registry key
  • 
    HKEY_CURRENT_USER\Software\Microsoft\WindowsNT\CurrentVersion\Windows
  • Write down the value of "Device" as you'll be using it soon
  • Locate the following registry key
  • 
    HKEY_USERS\.DEFAULT\Software\Microsoft\WindowsNT\CurrentVersion\Windows\ 
    
  • Copy the previous information into the field "Device"
  • Reboot your PC
That's it! Now you can print from a Windows NT service.

Warning!

Modifing your registry incorrectly can result in serious, system-wide problems. Therefore, use this advice at your own risk.

Acknowledgements

Thanks to my friend Maurizio Picco for his usefull help.



Comments

  • How can i do to print document from SYSTEM account ???

    Posted by Legacy on 01/16/2002 12:00am

    Originally posted by: Barbier J�r�me

    I have a NT Service which start with SYSTEM account.
    
    During my process i need to print document to a specific printer using 'ShellExecute' with 'printto' verb.
    But I don't manage to retrieve Driver and Port for my printer and the function failed..

    Best regards.

    Reply
  • Log from NT service without using Event Log

    Posted by Legacy on 02/19/2000 12:00am

    Originally posted by: Tibor Hellvig

    I have converted a program to NT service and now my logging to a regular text file no longer works. Can anyone help?

    Reply
  • This works for any program called by a service

    Posted by Legacy on 11/21/1999 12:00am

    Originally posted by: Bernard Cheung

    Thanks to this solution, I am able to use Windows NT's AT command or some Scheduler program to schedule print jobs of third party programs.

    cheers

    Bernard

    Reply
  • Where's the problem ?

    Posted by Legacy on 11/16/1999 12:00am

    Originally posted by: Bernard Alleysson

    I did not find any problem to print from a service I've written. I'm just using:

    m_hDC = CreateDC(
    _T("WINSPOOL"),
    pszDevice, NULL, pDevMode
    );

    where pszDevice is the UNC name of the printer ie
    \\server\printername

    IMHO, no registry copy needed

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds