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

334

Solution 1

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

Solution 2

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

Share:
334

Related videos on Youtube

adnaan.zohran
Author by

adnaan.zohran

Updated on September 18, 2022

Comments

  • adnaan.zohran
    adnaan.zohran over 1 year

    I have to download a file and was using downloadManager for it. The filename for the file resides in the Content-Disposition of the response header.

    Is there anyway of accessing the response header from DownloadManager.Request class or downloadManager could support this out of the box.

    I don't want to make a HEAD api call to the server and increase the server hit count. We can assume we don't have HEAD call functionality.

    • Balu Sangem
      Balu Sangem almost 6 years
      Seems not possible.
  • kralyk
    kralyk about 11 years
    I find it strangely eerie that you knew which 3rd party app I was referring to. ;)
  • Spence
    Spence about 11 years
    I could just tell by how you phrased it. I have a strong intuition relating to crappy software and stupid demands to have interactively logged-on sessions. (And I have to deal with this dog in a couple of sites. Don't even get me started about the upgrade we just did 3 weeks ago to the 2012 version-- my poor Customer was running one-off SQL scripts from the vendor for days after the upgrade was done just to get back basic functionality.)
  • kralyk
    kralyk about 11 years
    Very nice. Thanks for the insight, I'll get to work on it. (Now if they'd just make their ERP app's icons look like they weren't from 92)
  • kralyk
    kralyk about 11 years
    Thanks...this helps as well. You both have great answers to the issue.
  • Spence
    Spence about 11 years
    It does look pretty dated, doesn't it? I've never actually had to use it, thankfully. (I'd like to see the requirements for the Borland Database Engine dropped, personally... I think it is from '92... >smile<)
  • Spence
    Spence about 11 years
    The "manufacturer" is really, really anal about using their job scheduler. They pretty much demand it and make it a condition of support. It's crazy.
  • kralyk
    kralyk about 11 years
    We are also using CommVault's iOracle agent, but the 3rd party ERP support still requires a nightly EXP dump based on their app "just in case we can't use the CommVault restore". All it really does is an Oracle EXP dump nightly...I can easily script what it does, but they insist. EDIT: yeah what @EvanAnderson said
  • Stephane
    Stephane about 11 years
    Actually, BDE isn't so much of a problem. You can even package it with the application itself and not have to install it on the machine. It's not trivial because you have to extract all the binaries as well as the config file, but it works.
  • kralyk
    kralyk over 10 years
    @EvanAnderson - update. I'm messing around with letting Firedaemon Pro handle this now. Setting it up in interactive mode with a pre-script to map relevant drives seems to be working. I'll update later this week, but so far so good. It's "technically" logged on, but since this is a hosted VPS, it's OK with me (since the alternative is just leaving it as is)