3
Answers

Using Microsoft Office Automation running as Service (SYSTEM LOCAL)

Guillaume Lepinay

Guillaume Lepinay

13y
5.7k
1
Hello every body,

i'm new to this forum, so let me introduce myself quickly : my name is Guillaume, I live in France and work ad developer in a small company in Montpellier. (please excuse my bad english...)

Here is my problem :
I'm currently using C# to convert Microsoft Office document (Word, Excel, Powerpoint and Publisher) using the SaveAs module of Microsoft Office.

Here is a sample of code, working well to convert Word to PDF :
Microsoft.Office.Interop.Word.Application word = null;
Microsoft.Office.Interop.Word.Document d = null;
try
{
word = new Microsoft.Office.Interop.Word.Application();
word.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
word.Visible = true;
d = word.Documents.Open(source);
d.ExportAsFixedFormat(pdf, WdExportFormat.wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForPrint,
WdExportRange.wdExportAllDocument, 1, 1, WdExportItem.wdExportDocumentContent, false, true,
WdExportCreateBookmarks.wdExportCreateNoBookmarks, true, true, false);
}
catch (COMException ex){
Console.WriteLine("ERR > " + ex.Message + "\n" + ex.StackTrace);
}

This is not the full code, but the main processing code is here. This works perfectly when the program is running as a normal software, under an opened user  Windows Session (Tested with Office 2010, 2007, under Windows 7 and Windows Server 2008).

When I run this code as a Windows Service (SYSTEM LOCAL), then it doesn't work. So I searched some information on the internet, and I found this page from the Microsoft Website :
http://support.microsoft.com/?scid=kb%3Ben-us%3B257757&x=20&y=13

This page explain why it doesn't work when the code is running as service. So, finally I decided to use the application as a normal software, not as a Windows Service.

But few days ago I found a SDK nammed VeryPDF, that is using the same SaveAs module of Microsoft Office, and that is able to run as service.
So I searched more information to know how it works... but I didn't find anything.

Can some one help me and give me some advice to do this as service ? (VeryPDF is not open source, and cost around 18000$... so I cannot pay it :)).
Thank you very much for your help.


Answers (3)