Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

batch file help...

  • 09-09-2004 02:39PM
    #1
    Registered Users, Registered Users 2 Posts: 1,715 ✭✭✭


    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, Registered Users 2 Posts: 834 ✭✭✭fragile


    You should find what you are looking for here..

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


  • Registered Users, Registered Users 2 Posts: 1,715 ✭✭✭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


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 97,176 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, Registered Users 2 Posts: 1,715 ✭✭✭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
Advertisement