Hi ,We are getting exception System.InteropServices.ComException,Microsoft.office.interop.word. Message : Command failed Source : Microsoft Word Target Site : void Save()
Microsoft Word issue in windows server 2022 with non interactive session
Hi All , we have an application exe that uses Microsoft Word 2016 to generate Word documents and save the files. We are running this exe as a task scheduler in Gen3 Windows server 2022, when we run the scheduler with non-interactive session ( we tried using both service account and local account with when user is not logged in option ) we are getting Microsoft Word error while saving the word file in the server. When we run the exe manually , we are not facing the issue, also this exe is working fine on working fine on task scheduler on Windows server 2012
Windows for business | Windows Server | User experience | Other
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
2 answers
Sort by: Most helpful
-
Jack J Jun 25,306 Reputation points2025-02-03T13:09:03.48+00:00 @Rakshitha H P, please try the following steps to generate a word file by using exe in task scheduler.
First, please install Nuget-package DocumentFormat.OpenXml and use the following code.
static void Main(string[] args) { string filePath = @"C:\document.docx"; using (WordprocessingDocument wordDoc = WordprocessingDocument.Create(filePath, DocumentFormat.OpenXml.WordprocessingDocumentType.Document)) { MainDocumentPart mainPart = wordDoc.AddMainDocumentPart(); mainPart.Document = new Document(); Body body = new Body(); mainPart.Document.Append(body); Paragraph titleParagraph = new Paragraph(); Run titleRun = new Run(); titleRun.Append(new Text("This is Title")); titleParagraph.Append(titleRun); body.Append(titleParagraph); Paragraph bodyParagraph = new Paragraph(); Run bodyRun = new Run(); bodyRun.Append(new Text("This is Content")); bodyParagraph.Append(bodyRun); body.Append(bodyParagraph); } Console.WriteLine("Word doc has been generated"); }Second, please set the following option to set user account information:(please note that your current user account needs to set administrator power)
Third, please set the exe path in the action:
When you run the task in the task scheduler, the word file will be generated.
Hope my advice could help you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.