Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BeginDoc from a Service

Status
Not open for further replies.

colttaylor

Programmer
Aug 20, 2002
117
US
I've written a NT Service in Delphi 5 which receives directory change notification messages for an empty directory. Whenever a file gets created in that directory, my service reads it into a stringlist, formats it and then tries to print it.

Everything is working up to the "print it" part.
When the service calls printer.begindoc, it stops executing (I try to make a log entry right after the call to begindoc and that log entry never gets written out). The service still appears to be running, but my code stops right there.

Prior to calling the begindoc, I set the printer.printerindex so it is not that the software doesn't know where to print.

When I stop the service, that seems to break the program's trance. The log entries show that all of the printer.canvas.textout calls occur and that a printer.enddoc call finishs off the process. Nothing prints but no exceptions or logical errors occur.

Has anybody got any experience using printer.begindoc from a service? If not, has anybody ever successfully printed from a service in any language or by any other technique?
Any help would be appreciated!

Thanks!
Peace,
Colt


If it's stupid but it works, it isn't stupid
 
Hi Everyone,
I found my own solution.
First I copied the...

HKEY_CURRENT_USER\Software\Microsoft\WindowsNT\CurrentVersion\Windows\Device

...registry value to...

HKEY_USERS\.DEFAULT\Software\Microsoft\WindowsNT\CurrentVersion\Windows\Device

...and rebooted.

Take care everyone!
Peace,
Colt
That didn't seem to do any good, but the theory was good. It set up the target printer as the default printer for processes running on the localsystem account.

The next thing I tried was to change the service's login credentials to an account which had a printer defined. This actually worked and the utility is now running great!



If it's stupid but it works, it isn't stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top