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_USERSoftwareMicrosoftWindowsNTCurrentVersionWindows

  • Write down the value of "Device" as you’ll be using it soon
  • Locate the following registry key

  • HKEY_USERS.DEFAULTSoftwareMicrosoftWindowsNTCurrentVersionWindows 

  • 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.

More by Author

Must Read