How to launch Word from Windows Service using .NET?

P

present

Hi,

I wrote a Windows Service program using .NET 2.0 as below:
1) I added reference to Word COM library (version 11.0)
2) Added a method like below to convert an html file to Text file:
/// <summary>
/// Convert source file into text format using Word COM object
/// </summary>
public void ConvertToTextFile(String sourceFile, String resultFile)
{
Object missing = System.Reflection.Missing.Value;
Object fileSource = sourceFile;
Object fileResult = resultFile;

Word.Application app = null;
try
{
app = new Word.ApplicationClass();
app.Documents.Add(ref fileSource, ref missing, ref missing, ref
missing);
Word.Document currentDoc = (Word.Document)app.ActiveDocument;

// Save to text format
Object fileFormat = Word.WdSaveFormat.wdFormatText;

currentDoc.SaveAs(ref fileResult, ref fileFormat, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing,
ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);
}
finally
{
// Close the documents
if (app != null)
{
app.Documents.Close(ref missing, ref missing, ref missing);
app.Quit(ref missing, ref missing, ref missing);
}
}
}

When I test the mothod using a testing client, it works. But when I put
that method into a Windows Service running with System Account, the
service throws error message:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top