Microsoft Word issue in windows server 2022 with non interactive session

Rakshitha H P 0 Reputation points
2025-01-30T14:26:07.4233333+00:00

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 Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,726 questions
C#
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.
11,343 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jack J Jun 24,881 Reputation points Microsoft External Staff
    2025-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)

    User's image

    Third, please set the exe path in the action:

    User's image

    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.


  2. Rakshitha H P 0 Reputation points
    2025-02-03T13:11:26.0033333+00:00

    Hi ,We are getting exception System.InteropServices.ComException,Microsoft.office.interop.word. Message : Command failed Source : Microsoft Word Target Site : void Save()

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.