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

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.


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


First, are you sure you really need an interactive session ? Chances are you can actually run it inside a scheduled task if set it up property.

Now, assuming the above is not possible/practical/allowed:

You can setup your VM to automatically log in a user. The process is described here but here are the high points:

  • Open HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon in regedit
  • Create two registry entries DefaultUserNameandDefaultpassword`
  • Edit the AutoAdminLogonentry and set it to 1

(alternatively, you can just download and use AutoLogon)

I'm sure you can see the potential issue here so I won't elaborate.

Your second request is pretty easy to do with a batch. Here is a sample that uses blat:

tasklist | find "myprocess.exe"
if %ERRORLEVEL%==1  blat tasknotrunning.txt -to [email protected]

If you want to use the event log instead, then you can use the built-in eventcreate command like this:

tasklist | find "myprocess.exe"
if %ERRORLEVEL%==1  eventcreate.exe /L APPLICATION /ID 911 /D “task XXX is not running” /T INFORMATION

(I picked 911 here as event ID but you can use whatever you see fit as long as it doesn't conflict with something else).