Quantcast
Channel: Word for Developers forum
Viewing all articles
Browse latest Browse all 4350

in Windows 8.1, Exception is being thrown when the Word Automation(using office2007) run in System Service context.

$
0
0

Hello,

Below code which throws an exception, When run the Word2007 automation in System service context. This issue happened in Windows 8.1 system.

Guid clsid = new Guid("{000209FF-0000-0000-C000-000000000046}");               

 Type servreType = Type.GetTypeFromCLSID(clsid);;
 object theServer = Activator.CreateInstance(ServerType);

 Type typeof_Server = theServer.GetType();

 typeof_Server.InvokeMember("Visible", BindingFlags.SetProperty, null, theServer
                                     , new object[] { true });
 typeof_Server.InvokeMember("DisplayAlerts", BindingFlags.SetProperty
                                     , null, theServer, new object[] { false });

 object documents = typeof_Server.InvokeMember("Documents", BindingFlags.GetProperty, null, theServer, null);

 object theActiveDocument = documents.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, documents
                                                               , new object[] { objFileName0, Type.Missing, Type.Missing, Type.Missing
                                                               , Type.Missing, Type.Missing, Type.Missing, Type.Missing
                                                               , Type.Missing, Type.Missing, Type.Missing, Type.Missing
                                                               , Type.Missing, Type.Missing, Type.Missing, Type.Missing});

 try
 {
        object sections = theActiveDocument.GetType().InvokeMember("Sections", BindingFlags.GetProperty
                                                                   , null, theActiveDocument, null); // Exception thrown here.[
Exception from HRESULT: 0x800ADF21]
 }
 catch (Exception exp)
 {
        string strError = exp.Message;
 }

Thanks


karthikeyan


Viewing all articles
Browse latest Browse all 4350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>