I have an EC2 instance with Windows Server 2012 R2 with all the latest updates.

I made a service at first, and then a task to run a batch file to create a Microsoft Word report (using my custom C# program). I set the task to run with highest privileges and to be run as Administrator. While my batch file does get called, it fails. My batch file:

C:/WordGenerator.exe C:/report.docx > C:/word.log 2>&1

It errors out with an exception from the exe:

System.NullReferenceException: Object reference not set to an instance of an object.
    at InteropFunctions.Save(String opath)
    at Reporting.Report.generate()
    at Reporting.WordGenerator.run()

If I run the batch file manually, it finishes fine.

The above exception occurs when C# Word interop function tries to open a made report for further processing (so it effectively doesn't have permissions - can't find it).

  1. What I learned so far it that Windows may still run all services as the LOCAL SYSTEM account, and logs in to the given user (if any) on the fly.

  2. I also learned that services may run in a different sessions/security context as regular Administrator commands.

Can anyone help find a solution that works? I need to run a batch file on startup as Administrator (without login). I willing to go as far as simulating a login. We are experiencing other issues due to this not really being run as Administrator (what I gave was a simple case). Pictures for setup:

enter image description here

  • Looks like either path or permissions. – mdpc Sep 20 '14 at 1:52
  • Thank you for -1 whoever, suggestions to question are appreciated. @mdpc It is not the path, in the exe I did fileExists? -> true. Yes, it is permissions. But as you see, it is run as the only user account - Administrator. – jn1kk Sep 20 '14 at 1:57

The reason why this was failing was because of DCOM in Windows. I set mine to run as Administrator (in Identity) section.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.