Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

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?
Avatar of Kelly Hasenmueller
Kelly Hasenmueller
Flag of United States of America image

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"
:OLRUNNING


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"
:OLRUNNING
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

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
      else
strProgramPath = "c:\YOURPROGRAM\YOURPROGRAM.EXE"
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
      else
            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:
strProgramPath = "c:\YOURPROGRAM\YOURPROGRAM.EXE"

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,
Regards,
GFilipe
Avatar of sbornstein2
sbornstein2

ASKER

this worked great thanks