printing word doc from windows service

  • Thread starter Thread starter amchater
  • Start date Start date
A

amchater

I have been doing alot of looking around for a way to use the
Microsoft.Office.Interop classes to print word documents. It is very
easy to do from a normal windows application but it does not work from
a windows service.

The following line causes the service to hang.

Dim wordapp As Word.Application = New Word.Application

I dont even have a chance to turn of the UI stuff. Does anyone have
any idea how to use this stuff in a service? I would really
appreciate it.
 
Something that I have found, at least back when it was NT 4.0 was that if
the user did not log in interactively, the printer hive of the current user
in the registry was not populated.

At the time, the work around that we implemented was to have a dedicated
server always logged in with appropriate credentials and act as a print
queue server. We then simply asked this sever to process the documents and
notify the requestor (Web service, web application, windows application)
when the job was done. Sometimes, for long running reports, we just had the
server email the reports to the requestor.

Since then, the company dumped the code into a windows service. This
allowed us to not have a server logged into all the time, but we did leave
the report queue on a dedicated server and had the web services/windows
applications request the reports. The windows service must log in with
valid credentials and the account must be allowed to log in interactively (I
don't recall if we need to act as part of the OS as well).

I wonder if your issue is related to the issue we had.

Other things to check:

Does the windows service machine have MS Word (Professional or better
installed 2k+)
Does the windows service have the MS Office .Net Interop assemblies
installed

if yes to those, can you create the word application with createobject?

Dim objWordApp as object = createobject("Word.Application")
dim objWordDoc as object = objWordApp.Documents.Add...
when creating objects with createobject it is prolly best to release them as
thus:

objWordDoc.Close(save:=false)
objWordApp.Quit

'http://support.microsoft.com/kb/317109
System.Runtime.InteropServices.Marshal.ReleaseComObject(objWordApp)
System.Runtime.InteropServices.Marshal.ReleaseComObject(objWordDoc)


HTH
 
Something that I have found, at least back when it was NT 4.0 was that if
the user did not log in interactively, the printer hive of the current user
in the registry was not populated.

At the time, the work around that we implemented was to have a dedicated
server always logged in with appropriate credentials and act as a print
queue server. We then simply asked this sever to process the documents and
notify the requestor (Web service, web application, windows application)
when the job was done. Sometimes, for long running reports, we just had the
server email the reports to the requestor.

Since then, the company dumped the code into a windows service. This
allowed us to not have a server logged into all the time, but we did leave
the report queue on a dedicated server and had the web services/windows
applications request the reports. The windows service must log in with
valid credentials and the account must be allowed to log in interactively (I
don't recall if we need to act as part of the OS as well).

I wonder if your issue is related to the issue we had.

Other things to check:

Does the windows service machine have MS Word (Professional or better
installed 2k+)
Does the windows service have the MS Office .Net Interop assemblies
installed

if yes to those, can you create the word application with createobject?

Dim objWordApp as object = createobject("Word.Application")
dim objWordDoc as object = objWordApp.Documents.Add...
when creating objects with createobject it is prolly best to release them as
thus:

objWordDoc.Close(save:=false)
objWordApp.Quit

'http://support.microsoft.com/kb/317109
System.Runtime.InteropServices.Marshal.ReleaseComObject(objWordApp)
System.Runtime.InteropServices.Marshal.ReleaseComObject(objWordDoc)

HTH









- Show quoted text -

Thank you so much for the reply. I tried what you suggested but it
did not work. I really think that the problem is with the GUI that
the word.application object wants to use. If I try to open a windows
form from a service the same thing happens. Is there a way around
this. There is a way to turn the UI off but i cant do that until an
object instance is created. I would hope that there is another word
object that can be used. all I need to do is print. I dont care
about anything else.

I have thought of some other possibilites. If i could convert the DOC
into a PDF then I could Convert the PDF into a bitmap and images are
easily printed but im having trouble finding a Doc to PDF converter
that my service can hook into.
 
Back
Top