1

I've got a problem while opening Word 2007 (DOCX) document via Windows service (running by account with administrator privileges).

        object fileNameO = templateFilename;

        _application.Visible = visible;
        _application.DisplayAlerts = WdAlertLevel.wdAlertsNone;

        //opening document
        _document = _application.Documents.OpenNoRepairDialog(ref fileNameO,
                                              ref _missing,
                                              ref _truevalue,
                                              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);
        //activating document
        _document.Activate();

_document in _document.Activate(); is null (System.NullReferenceException: Object reference not set to an instance of an object.)

I've tried to open by Open and OpenNoRepairDialog methods.

It's quite strange because when I try to running thread (service) in console application everything is working fine !

Pls help :)

Kara
  • 6,115
  • 16
  • 50
  • 57
JJiro
  • 11
  • 1
  • 2
  • 3
    Please be aware that running Office unattended (either as a Windows Service or Web application) isn't supported: http://support.microsoft.com/kb/257757 - that being said, it might still work and sometimes the business requirements require it, but it's a world of pain :) – Michael Stum Mar 10 '11 at 17:31
  • I have used Exel in my web apps to genarate Exel files. The problem I had was to give correct permissions to application pool to use Exel. – Jayantha Lal Sirisena Mar 10 '11 at 17:35
  • See my answer to [this question][1]. It might help. [1]: http://stackoverflow.com/questions/1006923/automating-office-via-windows-service-on-server-2008/1680214#1680214 – Gary McGill Jul 20 '11 at 22:20

5 Answers5

1

Launch dcomcnfg.exe (Component Services)

Then Console Root->Component Services->Computers->My Computer->DCOM Config->Microsoft Word Document->Right Click(Properties)->Identity Tab

Then select interactive user instead of launching user. By setting this MSWordwill be executed with the rights of user that is currently logged on.

Yawar
  • 1,016
  • 1
  • 12
  • 14
0

check your com+ application security to clarify whether your service running account have relavant permissions for Word

Jayantha Lal Sirisena
  • 21,216
  • 11
  • 71
  • 92
0

I have tried all the above and nothing worked. Creating the following directory worked for me on Windows 10.

mkdir C:\Windows\SysWOW64\config\systemprofile\Desktop

The System Profile requires a Desktop folder to open Office files (Word, Excel etc.)

Now I can run my C# application as a service using LocalSystem.

Have a look at Automating Office via Windows Service on Server 2008

Imraan
  • 657
  • 1
  • 5
  • 10
0

Create the following directory: C:\Windows\SysWOW64\config\systemprofile\Desktop

andres101
  • 67
  • 3
0

Type dcomcnfg in the command prompt and press Enter; find and select Microsoft Word Document in the Applications list, then press the Properties button; Note: If you have Windows 2003\2008 then type dcomcnfg in the command prompt, expand the Component Services group, expand the Computers group, expand the My Computer group, expand the DCOM Config group, find and select the Microsoft Word Document->right mouse click->Properties. click the Identity tab. Check the "This user" checkbox, press Browse and specify the Administrator account; enter and re-enter the Administrator password;

http://www.neevia.com/support/examples/cr/?get=ex002aspnet

user1031186
  • 58
  • 1
  • 6