Click here to Skip to main content
11,409,516 members (43,944 online)
Rate this: bad
Please Sign up or sign in to vote.
I am trying to access Microsoft word instance through my service but I am getting this error
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)) ,
I have opened word document ( i can also see WINWORD.EXE in Task Manager) ,
I am using VS 2010 and MS Office 2003. Here is my code

    Dim fs As New FileStream("D:\log.txt", FileMode.OpenOrCreate, FileAccess.Write)
            Dim sw As New StreamWriter(fs)
            sw.BaseStream.Seek(0, SeekOrigin.End)
            Dim wordapp As Word.Application
            wordapp = Marshal.GetActiveObject("Word.Application")
            For Each doc As Word.Document In wordapp.Documents
                sw.WriteLine(doc.FullName.ToString() + "\n" +

if i use this code in windows form application it works perfect, but doesn’t works in windows service.Why is that for ? Windows Service Doesn’t support Microsoft.Office.Interop ? If it does work please guide.
Posted 22-Feb-13 0:58am
Edited 21-Mar-13 19:50pm
ArunAmalraj at 22-Feb-13 6:07am
Hello muneebalikiyani,

Check for User Rights.

It will not work if...Your application is running as administrator and WINWORD with normal user rights.
muneebalikiyani at 22-Feb-13 6:24am
thanks , but what can i do to make it work

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Run your service with your credentials - otherwise it won't be able to access Word running with your credentials.
Marcus Kramer at 22-Feb-13 9:37am
My 5.
muneebalikiyani at 26-Feb-13 23:19pm
I have done that also , i think Marshall.getactiveobject() doesn't works for windows services, please correct me if i am wrong

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 300
1 OriginalGriff 285
2 Dave Kreskowiak 115
3 Andy Lanng 115
4 Maciej Los 100
0 Sergey Alexandrovich Kryukov 8,731
1 OriginalGriff 6,895
2 Maciej Los 3,332
3 Abhinav S 3,248
4 Peter Leow 3,059

Advertise | Privacy | Mobile
Web04 | 2.8.150414.5 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100