I am trying to write a batch file that does two things:
- First it launches an installer (install.exe) which installs a program (program.exe).
- Second it launches an instance of the installed program (program.exe). This must be executed after the installation completes.
This would be relatively straightforward except that the installer needs administrator privileges and must run in a user context. Even with these restrictions this would still be relatively straightforward except that I am running this on an Azure Worker Role, which means two things:
- Elevated batch files must be run from a startup task.
- There is no user context for startup tasks in Azure worker roles.
It therefore appears that the solution is to run the installer as a Task Scheduler task in a real user context. However, this comes with the caveat that I would then need to wait for this task to finish before I could launch program.exe.
Thus, my question is: How do I wait on a Task Scheduler task to finish in a batch file?
Alternatively, I could daisy chain the two calls in my batch file within a single Task Scheduler task (Task Scheduler supports up to 16 sequential events in a single task [Citation Needed]).
However, if I take this approach my batch file will terminate as soon as the task is scheduled, not as soon as it finishes. Unfortunately, I must wait on it to finish before I can do any of the logic in my Worker Role. However, if I can check if a Task Scheduler task has finished from C# (WITHOUT admin privileges), then I can just wait on it there.
Thus a second viable answer would be to the question: How do I check if a Task Scheduler task has completed from C#?