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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(strComput er,strProc ess) then
else
strProgramPath = "c:\YOURPROGRAM\YOURPROGRA M.EXE"
set objShell = createobject("Wscript.Shel l")
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=imper sonate}!\\ " _
& strComputer & "\root\cimv2")
if objWMIService.ExecQuery(st rWMIQuery) .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\YOURPROGRA M.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
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(strComput
else
strProgramPath = "c:\YOURPROGRAM\YOURPROGRA
set objShell = createobject("Wscript.Shel
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=imper
& strComputer & "\root\cimv2")
if objWMIService.ExecQuery(st
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\YOURPROGRA
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
ASKER
this worked great thanks
Batch File A:
IF EXIST "C:\Documents and Settings\mylogin\Local Settings\Application Data\Microsoft\Outlook\~ou
"C:\Program Files\Microsoft Office\Office12\OUTLOOK.EX
:OLRUNNING
Batch File B:
IF EXIST "C:\Documents and Settings\mylogin\Local Settings\Application Data\Microsoft\Outlook\~ou
START "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EX
:OLRUNNING