Office Interop and AD account issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mrllittle
    New Member
    • Jan 2014
    • 2

    #1

    Office Interop and AD account issue

    I do not wish to get into a debate about the merits of using Microsoft Office to perform this task. I have argued endlessly that this is NOT the way to accomplish this but the powers that be have overridden me on numerous occasions. I understand too that Microsoft does NOT recommend using this method and does NOT support it. But here I am….

    Issue: I have created a console application that processes files by encrypting them with a password so they can be emailed. I have no issues processing images and PDF’s, both using iTextSharp, but there is a strange issue processing office documents. When I step through the studio they process without any issues no matter what active directory account I am logged in with. When deployed however office documents will not process unless it is running under my AD account. I know exactly where the error is generated. Here is the code below.

    Code:
    private void PasswordProtectWord(Datapassedin pa)
    {
       int num = 0;
       try
       {
          Microsoft.Office.Interop.Word._Application objWord = null;
          _Document objDoc = null;
          objWord =
    (Microsoft.Office.Interop.Word.Application)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("000209FF-0000-0000-C000-000000000046")));
    
                    objWord.Visible = false;
                    objWord.DisplayAlerts = WdAlertLevel.wdAlertsNone;
                    objWord.DisplayAutoCompleteTips = false;
                    objWord.DisplayDocumentInformationPanel = false;
                    objWord.DisplayRecentFiles = false;
                    objWord.ScreenUpdating = false;
                    object objValue = Missing.Value;
                    object objMissing = Type.Missing;
                    object docName = pa.DocName;
                    object password = pa.Password;
                    object passwordProtectedDocName = pa.Password_Protected_DocName;
                    object objTrue = true;
                    object objFalse = false;
                    object objReadOnly = configvalue.ObjReadOnly;
                    // open statement below does not open
                    objDoc = objWord.Documents.Open(ref docName, ref objValue, ref objReadOnly, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objFalse, ref objValue, ref objValue, ref objValue, ref objValue);
                    // null object error is thrown here when we attempt to activate.  I discovered this by placing flags in the code line
                    objDoc.Activate();
                    objDoc.SaveAs2(ref passwordProtectedDocName, ref objValue, ref objValue, ref password, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue, ref objValue);
                    objDoc.Close(objTrue, Type.Missing, Type.Missing);
                    Marshal.ReleaseComObject(objDoc);
                    objWord.Quit(objFalse, Type.Missing, Type.Missing);
                    Marshal.ReleaseComObject(objWord);
                }
                catch (Exception ex)
                {
                    UpdateErrorLogAndSendEmail(string.Format("{0} And {1} - {2} - {3}", ex.Message, ex.InnerException.Message,  num.ToString(), pa.Password_Protected_DocName), ex.Source, "", configvalue.Bcc);
                }
            }
    Okay here are some of the steps I have taken, albeit the extreme steps, to resolve the issue.

    We attempted to rebuild the entire project using the service ID rather than my own account. Then logged into the server using the service ID deploying the code and creating the console job.

    Not only did this not work it also repeated the behavior by allowing the console application to run when my ID was used as the AD authority.

    Tried to duplicate all permissions from my AD account to the service ID. Same results as above.

    Items to consider:

    1. Scheduled task processes all image and PDF files no matter what AD account is used.
    2. No AD account works on office documents when not ran under my account. I only mentioned the service account above but we have also tried system administration accounts to run the scheduled task as well.
    3. All accounts attempting to run the scheduled task logged into the deployment servers and opened word/excel documents to ensure we have temp space on the server.
    4. Office settings for all accounts were compared and matched to my settings.

    Any information or suggestions would be greatly appreciated.
    Last edited by mrllittle; Jan 8 '14, 01:13 PM. Reason: add a thank you
  • mrllittle
    New Member
    • Jan 2014
    • 2

    #2
    I actually received a response on another site which lead me to the answer. I do not completely like the solution but I followed the steps below to get the service to process Office documents.

    1. Ran "mmc -32" command.
    2. Selected menu options "file~Add/Remove Snap-in" and added the "Component Services."
    3. Navigated this path in component services "Component Services/Computers/My Computer/DCOM Config."
    4. On both the "Microsoft Word 97 - 2003 Document" and "Microsoft Excel Application" I set the "This user." setting to my service AD account on the "Identity" tab.

    As stated, I do not like the solution but it is working. I still do not know why my AD account worked on all these machines without my being logged in or deploying the software. If anyone has a theory I would be happy to listen.

    This is fixed but I do not know how to mark it as answered.

    Comment

    Working...