Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

batch file help...

Options
  • 09-09-2004 3:39pm
    #1
    Registered Users Posts: 1,711 ✭✭✭


    hi

    i need to write a simple batch file to chack if a certain process "X" is running, if not, to start it.

    any help appreciated....


Comments

  • Registered Users Posts: 834 ✭✭✭fragile


    You should find what you are looking for here..

    http://www.robvanderwoude.com/processes.html


  • Registered Users Posts: 384 ✭✭mrhappy42


    Some applications will only run once (its a setting compiled into the app) if yours is one of these than you can just launch it repeatitly...i.e dont botter checking just run it in a loop with a sleep statement.

    The above batch utility will give you if the app is running but the condition to then trigger its start can be messy.


  • Registered Users Posts: 1,711 ✭✭✭Gryzor


    mrhappy42 wrote:
    Some applications will only run once (its a setting compiled into the app) if yours is one of these than you can just launch it repeatitly...i.e dont botter checking just run it in a loop with a sleep statement.

    The above batch utility will give you if the app is running but the condition to then trigger its start can be messy.

    yeah tried that allready....it'll run as many times as its launched... :confused: ...i'm just looking for the code to "check if blahblah.exe is running, if it is, grand, if not run it.

    sounds nice and easy in english... :D


  • Registered Users Posts: 384 ✭✭mrhappy42


    If you are the only one launching this app ever then you could do a 'start' command which has some nice options like waiting until the app is finished...if it is then guess what you need to start it again.

    If however others can start your app you need to use the tools above...


  • Registered Users Posts: 384 ✭✭mrhappy42


    1 top
    2 TLIST eq yourapp > list.bat
    3 echo yourapp >> list.bat
    4 list.bat
    5 sleep x
    6 goto top

    very dirty code but the idea is in line 2 to direct your app into a file...if the app is running it will enter this into the file. Line 3 will append to this file your app name that you want to run. line 4 will kick start this file with all the information in it.

    the idea is that if the program is running the file 'list.bat' will be so garbeled that when you run it in line 4 it will just report errors.

    However if your app is not running the only entry in 'list.bat' will be entry 3 which will run your app.

    not sure what exact output is from line 2 when nothing happens but might work.


  • Advertisement
  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 91,686 Mod ✭✭✭✭Capt'n Midnight


    :top
    pslist | find /I "app"
    if errorlevel 1 app
    choice /T:Y,10
    goto top

    Not debugged or tested.
    pslist - ntinternals site
    find should return an errorlevel or 0 if found (or visa versa)
    choice comes with win9x

    The problem with MANY Microsoft consle commands it that they keep changing the sythax and defaults so I've given up using many of them.


  • Registered Users Posts: 1,711 ✭✭✭Gryzor


    thanks lads....i also asked the question on Experts-exchange.com..this was the answer and it works a treat.

    This script should do the trick; simply define the process to be started at the beginning of the script. You need to install the Support Tools if you haven't done so yet, as the script needs tlist.exe. Don't install them from the W2k CD, download the current version from the link:
    Windows 2000 SP4 Support Tools
    http://www.microsoft.com/windows2000/downloads/servicepacks/SP4/supporttools.asp

    ====8<----[StartApp.cmd]----
    @echo off
    setlocal
    set Process=%Systemroot%\system32\calc.exe

    for %%a in ("%Process%") do set ProcessName=%%~nxa

    tlist.exe | find /i "%ProcessName%" >NUL
    if errorlevel 1 start "" "%Process%"
    ====8<----[StartApp.cmd]----


Advertisement