[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Startup EXE through Task Scheduler?

Posted on 2012-08-21
4
Medium Priority
?
697 Views
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?
0
Comment
Question by:sbornstein2
4 Comments
 
LVL 2

Expert Comment

by:Kelly Hasenmueller
ID: 38317292
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
0
 
LVL 85

Accepted Solution

by:
oBdA earned 1020 total points
ID: 38317318
Try this batch script; just replace Notepad.exe with your program and add your command line arguments (optional):
@echo off
setlocal
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

0
 
LVL 2

Expert Comment

by:gfilipe
ID: 38317338
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
0
 

Author Closing Comment

by:sbornstein2
ID: 38332737
this worked great thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
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…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

834 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