Startup EXE through Task Scheduler?

Posted on 2012-08-21
Last Modified: 2012-08-25
Hello all,

I was thinking about putting this in my startup programs but I have an windows forms application exe of course.  I want to run a task scheduler every evening at like 6PM where I check if the program is not started to start it.   Its possible someone would close the window so that is why I want a batch file or something where I can make sure its running at a certain time before it does its processing at 8PM. I don't want multiple versions though just the one started.  How can I do this?  Any batch file I can use to check etc?
Question by:sbornstein2
    LVL 2

    Expert Comment

    Hope this helps:

    Batch File A:

    IF EXIST "C:\Documents and Settings\mylogin\Local Settings\Application Data\Microsoft\Outlook\~outlook.ost.tmp" GOTO OLRUNNING
    "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE  /recycle"

    Batch File B:
    IF EXIST "C:\Documents and Settings\mylogin\Local Settings\Application Data\Microsoft\Outlook\~outlook.ost.tmp" GOTO OLRUNNING
    START "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE  /recycle"
    LVL 82

    Accepted Solution

    Try this batch script; just replace Notepad.exe with your program and add your command line arguments (optional):
    @echo off
    REM Program name including extension:
    set Program=Notepad.exe
    set Args=
    for %%a in ("%Program%") do set ImageName=%%~nxa
    tasklist /FI "USERNAME eq %UserName%" /FI "IMAGENAME eq %ImageName%" | find /i "%ImageName%" >NUL
    if not errorlevel 1 (
      echo %Program% is already running.
      goto :eof
    echo %Program% is not running yet, starting ...
    start "" "%Program%" %Args%

    Open in new window

    LVL 2

    Expert Comment


    I believe you can do this by using a vbscript.
    What I would do is, create the script, and then add the script as a service.

    here goes an example:
    option explicit
    DIM strComputer,strProcess

    strComputer = "." ' local computer
    strProcess = "YOUREXECUTEBLE.EXE"

    ' Check if process is running on specified computer (. = local computer)
    if isProcessRunning(strComputer,strProcess) then
    set objShell = createobject("Wscript.Shell")
    objShell.Run strProgramPath      

    end if

    ' Function to check if a process is running
    function isProcessRunning(byval strComputer,byval strProcessName)

          Dim objWMIService, strWMIQuery

          strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"
          Set objWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" _
                      & strComputer & "\root\cimv2")

          if objWMIService.ExecQuery(strWMIQuery).Count > 0 then
                isProcessRunning = true
                isProcessRunning = false
          end if

    end function

    You should only replace both this lines:
    strProcess = "YOUREXECUTEBLE.EXE"
    In case the program stops, you should state where this program should be started:

    Once you have this script tunned, you can both add it to your startup or eventually add it as a service.

    Hope this is helps,

    Author Closing Comment

    this worked great thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
    Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now