• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 701
  • Last Modified:

Startup EXE through Task Scheduler?

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?
1 Solution
Kelly HasenmuellerComputer Systems Administrator Commented:
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"
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


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

' 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:
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,
sbornstein2Author Commented:
this worked great thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now