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.