Solved

How to Print from an NT Service ?

Posted on 2000-04-06
8
164 Views
Last Modified: 2013-12-03
Hi,
I have a program which runs as NT service. It generates log messages and these messages are to be printed.

Can anyone tell me how I can print from a program running as service(even in the absence of any user loggin to that machine)

thanx
Prashanth
0
Comment
Question by:fidodido
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 

Author Comment

by:fidodido
ID: 2692334
Adjusted points from 50 to 100
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2692367
If you mean displaying the message on the screen, use MessageBox(... MB_SERVICE_NOTIFICATION )
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2692369
If you want to use a printer, use the standard spooler API like WritePrinter or StartJob etc.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 15

Expert Comment

by:NickRepin
ID: 2692397
I mean, StartDoc() etc
0
 

Author Comment

by:fidodido
ID: 2692451
Hi,

Yeah ! I want to print and not display a message box !

Let me eloborate my problem further.
The program prints properly when run in non-service mode. The printer routine querie the follwoing registry key "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\" and the "Device" string value.

But when I run in service mode, the follwoing registry key is queried "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows NT\CurrentVersion\Windows" and the Device string value. If this registry entry is present in the system, printing happens properly even in the service mode.

Now my question is, is there any way I can install a printer at system level ("Default user") so that the later registry key gets created and my application works fine?

thanx
Prashanth
0
 

Author Comment

by:fidodido
ID: 2692469
Hi,

Yeah ! I want to print and not display a message box !

Let me eloborate my problem further.
The program prints properly when run in non-service mode. The printer routine querie the follwoing registry key "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\" and the "Device" string value.

But when I run in service mode, the follwoing registry key is queried "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows NT\CurrentVersion\Windows" and the Device string value. If this registry entry is present in the system, printing happens properly even in the service mode.

Now my question is, is there any way I can install a printer at system level ("Default user") so that the later registry key gets created and my application works fine?

thanx
Prashanth
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2692636
Now I see...

Well, if you write a program for sale, then you definitely have to provide the special dialog in the setup program (or in the separate configuration program) that will ask the user to specify the printer which will be used for the service. Store the printer name under HKLM\Software\Your company\Your program\.
Keep in mind that there may be several printers installed and the user may use a one printer to print the documents and another one to print the log.

It's impossible to setup the printer in such way that it will appear under HKCU\.DEFAULT key.
But you may enter the Device value under HKCU\.DEFAULT manually by the registry editor or by using the method described in:

"Modifying Ntuser.dat Hive So New Users Get Defined Settings"
http://support.microsoft.com/support/kb/articles/Q146/0/50.asp

"How to Add a Default Printer for All New Users"
http://support.microsoft.com/support/kb/articles/Q252/3/88.ASP

Alternatively, when you program runs in the 'normal' mode, it can check if there is any value under HKCU\.DEFAULT\Device. If no, your program may copy to that key the value from the HKCU\CurrentUser\Device.
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 100 total points
ID: 2692638
That is the answer.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question