1. Sivaprakash BKR
  2. PowerBuilder
  3. Tuesday, 19 September 2023 07:47 AM UTC


PB 2022 B 2819, Application run as a Windows Service

When the control hits the command PrintGetPrinter(), it seems the application re-starts from the beginning.   In my windows service application, I need to set the printer to another printer (CutePDF), print a report, switch back to original printer.  

On execution, the control didn't go beyond the command PrintGetPrinter() command.  Full code is

ls_current_printer = PrintGetPrinter()
ls_pdf_printer     = 'CutePDF Writer'
ls_result = tab_1.tabpage_2.dw_report.Modify("Datawindow.Export.PDF.Method = Distill!")
ls_result = tab_1.tabpage_2.dw_report.Modify("DataWindow.Print.PrinterName = '" + ls_pdf_printer + "'")
ls_result = tab_1.tabpage_2.dw_report.Modify("Datawindow.Export.PDF.Distill.CustomPostScript = Yes")
	// write to the file
ll_ret = tab_1.tabpage_2.dw_report.SaveAs(ls_filename, PDF!, True)
If ll_ret <> 1 Then
	MessageBox('Elifa', 'Some error occurred while saving the File. Try Again. If problem persists contact Elite Computers Inc.')
	Return ''
End If
ls_result = tab_1.tabpage_2.dw_report.Modify("DataWindow.Print.PrinterName = '" + ls_current_printer + "'")
ls_result = tab_1.tabpage_2.dw_report.Modify("Datawindow.Export.PDF.Distill.CustomPostScript = 0")
ll_ret = PrintSetPrinter(ls_current_printer)

Both commands, PrintGetPrinter and PrintSetPrinter fails to execute in windows service program.   That works find when run from the powerbuilder ide as a normal windows application.

Is that normal behavior?

If Yes, is there any other way that I can print a report to a pdf file?  [ NativePDF fails when there are UNICODE contents.  Bug no. 10700 ]

Happiness Always
BKR Sivaprakash


Andreas Mykonios Accepted Answer Pending Moderation
  1. Tuesday, 19 September 2023 08:30 AM UTC
  2. PowerBuilder
  3. # 1


Services are executed using special accounts. One thing you can try is to make your service run under a specific user account (example: use your account as a test). Check if those commands are executed right. If yes, then set your service to be executed under an existing account that can see and use the printers that you need, and have all appropriate privileges - rights.


  1. Chris Pollach @Appeon
  2. Tuesday, 19 September 2023 16:50 PM UTC
Hmmmm... <sad> now. :-(
  1. Helpful
  1. Sivaprakash BKR
  2. Wednesday, 20 September 2023 07:02 AM UTC
Thanks Andreas, Chris, John

Yes, I use NativePDF , if there no no unicode contents in the report. It works fine.

CutePDF installs Ghostscript for its processing, [ from my memory ] and we don't re-install ghostscript again. It works fine when run as a windows application.

  1. Helpful
  1. David Peace (Powersoft)
  2. Wednesday, 20 September 2023 13:57 PM UTC
If my memory serves me correctly Printers exist in the User Environment, but a windows service is not running in a user environment. So probably using printers is going to be problematic.

We have used Roland's PBNiServ with great success, but we do not try and print from this.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 19 September 2023 17:36 PM UTC
  2. PowerBuilder
  3. # 2

Hi, Sivaprakash - 

I believe the problem MAY be due to your running a visual application as a (non-visual) Windows service. According to Microsoft and other sources, a service application does not a visual interface. I refer you to the first sentence in the following web page regarding Interactive Services:


It appears from the code snippet you posted that you are running a GUI application that contains one or more windows, a tab control and DataWindows... all visual elements. This may the cause of your issue and it just so happens that the app halts and restarts when the PrintGetPrinter PowerScript function is called. I'm dubious you will be able to get a visual application working as a Windows service.

In case you have not considered it, I will suggest you examine the PBNIServ product developed and offered by Roland Smith:


In my estimation, this would be the correct and proper way to run PB code/functionality as a Windows service application.

Best regards, John

There are no comments made yet.
  • Page :
  • 1

There are no replies made for this question yet.
However, you are not allowed to reply to this question.