Situation
I have a batch script that prepares some files, executes a program (.exe
) and then deletes said files.
This task should run hourly, so I'm trying to configure this using Scheduled Tasks. The problem is that the previously mentioned program does not run properly when invoked from the task (neither via the .bat
script, nor when calling the .exe
directly), but I don't get any warning or error messages in the logs.
Setup
The task is configured to run as a Windows Service Account that has all the privileges set properly. When using this account to logon via RDP, I can execute the .bat
and .exe
directly without problems, but still the task appears to do nothing. This is easily observed because the program always modifies a file, and the modified on timestamp does not change through the task.
In the scheduled task logs I get the information messages for the task starting a process, exiting, etc. The "result code", however, is 111
(tried to Google this without luck, the only association I get is "file name is too long", which is just completely irrelevant AFAIK). In the application logs, I get absolutely nothing.
What I suspect is the problem
The program is an old monstrosity that spawns some sort of splash screen (it's actually a normal window), even though the GUI is not needed because it requires no interaction and closes itself after operations. The window appears for about 2 seconds.
I suspect that this requirement for a GUI has something to do with the task failing, but I'm not sure. When I log in with the user that the task runs under (via RDP), no window appears when I start the scheduled task.
Edit about the GUI
I've built a very small C# executable that launches the program without the main window (using ProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden
). Even this way, the scheduled task still does not succeed to launch the program correctly, but the return code is now 0
.
Update
When I configure the task to say "run whether the user is logged on or not", and the run with highest privileges
option is unchecked, the error value is 2147943859
.
What can I do to troubleshoot?
OS = Windows Server 2008 R2 SP1
If more info is needed, please let me know in the comments.
Best Answer
I believe your problem has to do with either the permissions of the account being used to run the task, or the context of the account as exists when trying to run the task.
Test for Console Session Requirement
It's possible your .EXE must be run in
Console
session (aka Session 0) on the computer. To test for this:QWINSTA
, observe theSESSIONNAME
column, and confirm the>
indicator is next toconsole
, in other words it should appear as>console
)If the task runs correctly, try scheduling the task with
SCHTASKS.EXE
using the/IT
parameter. Failing that, you may have no choice but to configure the computer to automatically log on as your service user account and run the task as a startup program.Check Permissions
Additionally, as I've already suggested, check the following to confirm the account used to run the task is properly permissioned:
Computer Configuration/Windows Settings/Security Settings/Local Policies/User Rights Assignments
)Effective Permissions
tab in the file/folder's Properties atSecurity > Advanced
Additional things to check/try
Add some logging to your batch file. After every line it executes, have it write some output to a log file so you know where it's getting stuck. For example:
Try running your .EXE with
START
, for exampleSTART "myTitle" "C:\full\path\to\my.EXE"