question

YunHeeRo-1652 avatar image
1 Vote"
YunHeeRo-1652 asked JackJJun-MSFT commented

Word 2019 Administrator Authority Exception

Hello,

I am providing translated content. Please forgive any grammatical errors.

I have a program developed using C# and referencing the Microsoft.Office.Interop.Word assembly.
- Assembly Version: 15.0.0.0
- Development Environment: Windows 10 (64-bit), Visual Studio 2019
- Office Version: 2019

When you implement a program to run with administrator privileges, the following exceptions occur when creating Word application objects:
(Not in debug mode, exceptions occur when programs are run as executables.)

Exception message:
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

I have attached some codes.


Form1.cs
public partial class Form1 : Form
{
Microsoft.Office.Interop.Word.Application wordApp = null;

 public Form1()
 {
     InitializeComponent();
 }

 private void Button1_Click(object sender, EventArgs e)
 {
     try
     {
         wordApp = new Microsoft.Office.Interop.Word.Application();
         MessageBox.Show("Execute");
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }

 private void Button2_Click(object sender, EventArgs e)
 {
     if (wordApp != null)
     {
         wordApp.Quit();
         wordApp = null;
         MessageBox.Show("Quit");
     }
 }

}

app.manifest
..
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
..


An error occurs if the requestedExecutionLevel value in the app.manifest file of the C# project is "requireAdministrator".
(If you change to asInvoker, there is no error.)

Why is there an error in Word 2019?
I also want to know the solution.

dotnet-csharpoffice-vba-dev
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
Your problem is related to the code in Word, I changed the tag to office-vba-dev. The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

1 Vote 1 ·

@unHeeRo-1652, Welcome to Microsoft Q&A, based on my test, I could not reproduce your problem. Even if I used same environment, there is no error for me whether I set or not set requestedExecutionLevel's value to be requireAdministrator.

Here I have two suggestions:
1. I suggest that you could create a new local administartor and try to use the related code.
2. Please try to reinstall your office software.

0 Votes 0 ·

Thank you for answer.

I would like to attach the project source code and executable file that I tested, but is there any way to attach it?

1 Vote 1 ·

@YunHeeRo-1652, thanks for the feedback, based on my test, there is no error for me to use the code. If you want to share the project with me, Please upload your project to onedrive or Github, then shared the link here.

0 Votes 0 ·
Show more comments

I'm not an Office 2019 user so this is a guess.

For security purposes when an elevated process tries to instantiate a COM server the COM runtime only refers to the per-machine (i.e., HKLM) COM registrations.

My understanding is that Office 2019 is installed using C2R (Click to Run). I could be wrong, but I think that C2R applications are installed to a user's profile and the related COM registration is per-user. If my understanding is correct then that would explain the problem.

Is the elevated process that attempts to automate Word running under the same account used when Office was installed?

0 Votes 0 ·

Thank you for answer.

Yes, the process to automate Word and the account used to install Office were done with the same administrator account.

0 Votes 0 ·

0 Answers