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:
Failure 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).
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.
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: