473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. private void PasswordProtectWord(Datapassedin pa)
  2. {
  3.    int num = 0;
  4.    try
  5.    {
  6.       Microsoft.Office.Interop.Word._Application objWord = null;
  7.       _Document objDoc = null;
  8.       objWord =
  9. (Microsoft.Office.Interop.Word.Application)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("000209FF-0000-0000-C000-000000000046")));
  10.  
  11.                 objWord.Visible = false;
  12.                 objWord.DisplayAlerts = WdAlertLevel.wdAlertsNone;
  13.                 objWord.DisplayAutoCompleteTips = false;
  14.                 objWord.DisplayDocumentInformationPanel = false;
  15.                 objWord.DisplayRecentFiles = false;
  16.                 objWord.ScreenUpdating = false;
  17.                 object objValue = Missing.Value;
  18.                 object objMissing = Type.Missing;
  19.                 object docName = pa.DocName;
  20.                 object password = pa.Password;
  21.                 object passwordProtectedDocName = pa.Password_Protected_DocName;
  22.                 object objTrue = true;
  23.                 object objFalse = false;
  24.                 object objReadOnly = configvalue.ObjReadOnly;
  25.                 // open statement below does not open
  26.                 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);
  27.                 // null object error is thrown here when we attempt to activate.  I discovered this by placing flags in the code line
  28.                 objDoc.Activate();
  29.                 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);
  30.                 objDoc.Close(objTrue, Type.Missing, Type.Missing);
  31.                 Marshal.ReleaseComObject(objDoc);
  32.                 objWord.Quit(objFalse, Type.Missing, Type.Missing);
  33.                 Marshal.ReleaseComObject(objWord);
  34.             }
  35.             catch (Exception ex)
  36.             {
  37.                 UpdateErrorLogAndSendEmail(string.Format("{0} And {1} - {2} - {3}", ex.Message, ex.InnerException.Message,  num.ToString(), pa.Password_Protected_DocName), ex.Source, "", configvalue.Bcc);
  38.             }
  39.         }
  40.  
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.
Jan 8 '14 #1
1 1684
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.
Jan 9 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stu | last post by:
Hi, I am trying to open a word document from an asp.net page but I keep getting an access denied error when I try to create an instance of the word applications. I have created references to...
1
by: Stephen Noronha | last post by:
Hi, I am trying a sample app to send an email from my app I am getting a "type not defined error" I have added "Office and Outlook" COM component but still I am getting this error... Please...
2
by: William LaMartin | last post by:
I have created a program that allows for the automation of things in Word documents, like changing the values of DocVariables and the links to Excel Sheets. I did it using interoperoperatability,...
1
by: R Reyes | last post by:
ISSUE (reposted) =========================== Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? For many people, they say they add the...
1
by: Alan T | last post by:
VS 2005 and MS Office 2003 installed. I can include Microsoft.Office.Core and Word in the references so I can add the using Microsoft.Office.Interop.Word. However, my workmate cannot do the...
2
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a...
1
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
2
by: RodneyAnonymous | last post by:
I've got some code for composing an e-mail from the contents of an RTF box. The first time I execute it, everything works fine. If I close my app and then re-run it, however, I always receive the...
3
OuTCasT
by: OuTCasT | last post by:
Hi I have created an asp.net project that exports items from datagridview to and outlook calendar This is the code that i have used.. Dim body As String Dim ends As String ...
0
by: Jason Hamilton | last post by:
Hey all, I have written a Windows Forms application in VB.NET that creates a WCF Server. This server uses the Microsoft.Office.Interop.Access library to get a list of all of the MS Access...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.