Task Scheduler: Login to a session at startup and start a desktop app

scheduled-taskwindows-server-2008-r2

ISSUE:

I have a Windows 2008 R2 VM that runs a 3rd party ERP system. They have a utility that will run scheduled jobs to backup the Oracle database and their app data nightly with a 7 day rotation.

The problem is that it must run as a desktop app interactively within a session. It can't run as a service. While I'm not thrilled about leaving an account logged in, I've learned to allow it. The primary issue here is that if the server gets rebooted it can be days before I realize that the account is no longer logged into the server with the app open.

QUESTION:

Can (and if so, how) I create a task that runs at startup that logs a user onto the VM (creating a session) and launches an app on that session's desktop?

OR

If this is too difficult or not possible, anyone got ideas on how to check and see if this app is running in that account's session and if not send an alert? I'm cool with even a custom event log error since I can pick that up through remote monitoring.

Best Answer

I'm assuming that the program needs to display its UI and that you can't just run it non-interactively. (I love these "gems" of software...)

Here's what I'd do, personally:

  • Configure the server computer with an AutoAdminLogon as the user you want to run the application as. This will cause the server's console to logon as this user automatically on boot.

  • Add a script to the autologon user's personal "Startup" group that starts the task asynchronously, monitors the process list for the task being present (I'd use WMIC PROCESS LIST, personally), alert if the task goes missing from the process list and, if so-desired, restart the process. I'd also lock the workstation, too.

The script in the Startup group could be as simple as (calling the program you've got to run eqalert.exe):

@echo off
:restart
start "" "C:\Program Files\EQFU\EQWin32\eqalert.exe"
:check_loop
rem Delay 30 seconds between checks
ping -n 30 127.0.0.1 >NUL 2>NUL
wmic process list | find /i "eqalert.exe" >NUL 2>NUL
if not errorlevel 1 goto check_loop
echo eqalert.exe not running - restarting
eventcreate /T ERROR /ID 1 /L APPLICATION /D "eqalert.exe not running - restarting"
goto restart

This script assumes that there will only be one instance of the task running and is only check for the task's presence in the process list. If the process hangs and otherwise dies this script wouldn't catch that. (Monitoring if the program is "responding" to Windows-- i.e. if its message pump is still-- erm-- pumping-- is a more involved prospect.)