Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file? How to tell if a prog is running. If not, run?  (Read 12574 times)

0 Members and 1 Guest are viewing this topic.

AaronStarr

    Topic Starter


    Rookie

    Batch file? How to tell if a prog is running. If not, run?
    « on: June 14, 2010, 01:02:38 PM »
    I am writing a simple batch file to start multiple programs.

    Ex.:

    start /d "C:\Program Files\RocketDock" RocketDock.exe
    start /d "C:\Program Files\TrayClock" trayclock.exe
    start /d "C:\Program Files\SystemScheduler" WScheduler.exe
    cmd.exe

    What command(s) do I use to have the batch file FIRST check (automatically) to see if a program is running, and run the program if it is NOT already running?

    [[ Thanks in advance, I've looked and I just can't seem to find the answer. ]]


    marvinengland



      Hopeful

      Thanked: 11
      Re: Batch file? How to tell if a prog is running. If not, run?
      « Reply #1 on: June 14, 2010, 01:29:45 PM »
      http://www.computerhope.com/download/winxp.htm

      Download tasklist.exe   and findstr "myprog"  from output of tasklist
      USA

      Salmon Trout

      • Guest
      Re: Batch file? How to tell if a prog is running. If not, run?
      « Reply #2 on: June 14, 2010, 01:39:52 PM »
      example

      Code: [Select]
      tasklist | findstr "RocketDock.exe">nul || start /d "C:\Program Files\RocketDock" RocketDock.exe

      AaronStarr

        Topic Starter


        Rookie

        Re: Batch file? How to tell if a prog is running. If not, run?
        « Reply #3 on: June 14, 2010, 02:12:15 PM »
        Thanks to both of you. That's exactly what I was looking for. I just recently started dabbling around with batch files to help me with productivity.

        Your insight is much appreciated.

        AaronStarr

          Topic Starter


          Rookie

          Re: Batch file? How to tell if a prog is running. If not, run?
          « Reply #4 on: June 16, 2010, 11:39:59 PM »
          Oops. Actually, it didn't work exactly.

          I downloaded 'tasklist.exe' and installed that (as *marvinengland* suggested). And then I used the code that *Salmon Trout* mentioned. I thought it worked, but it didn't.

          When I run it in a batch file, I get: 'ERROR: Class not registered'... and it runs the program anyway. This happens whether the program was already running or not.

          What am I doing wrong?

          I appreciate the help.  :)

          Salmon Trout

          • Guest
          Re: Batch file? How to tell if a prog is running. If not, run?
          « Reply #5 on: June 17, 2010, 12:06:34 AM »
          When I run it in a batch file, I get: 'ERROR: Class not registered'... and it runs the program anyway.

          That error means that a COM object is not registered correctly, I believe. You have a software setup problem.

          Does tasklist work on its own?



          MendMyComputer



            Rookie

            Thanked: 5
            • Yes
            • MendMyComputer
          • Experience: Experienced
          • OS: Windows XP
          Re: Batch file? How to tell if a prog is running. If not, run?
          « Reply #6 on: June 17, 2010, 02:26:17 AM »
          I am writing a simple batch file to start multiple programs.

          Ex.:

          start /d "C:\Program Files\RocketDock" RocketDock.exe
          start /d "C:\Program Files\TrayClock" trayclock.exe
          start /d "C:\Program Files\SystemScheduler" WScheduler.exe
          cmd.exe

          What command(s) do I use to have the batch file FIRST check (automatically) to see if a program is running, and run the program if it is NOT already running?

          [[ Thanks in advance, I've looked and I just can't seem to find the answer. ]]



          My input might be a little late on this one but I used to do lots of bat files for this sort of thing until i found a free app called autohotkey, which has very good documentation and how to's and will allow you to do this task very easily. Take a look at it here as it may be what you're looking for, and can do so much more than just this www.autohotkey.com
          ---------------------------------------------------------------------------
          I work at  MendMyComputer

          AaronStarr

            Topic Starter


            Rookie

            Re: Batch file? How to tell if a prog is running. If not, run?
            « Reply #7 on: June 19, 2010, 04:29:02 AM »
            THANKS *MendMyComputer* !!

            I looked into That "AutoHotKey" program.

            It's Awesome... and Powerful too. Wow. That prog. solves a lot of problems for me (that I was trying to figure out with .bat files).

            Thanks again.

            MendMyComputer



              Rookie

              Thanked: 5
              • Yes
              • MendMyComputer
            • Experience: Experienced
            • OS: Windows XP
            Re: Batch file? How to tell if a prog is running. If not, run?
            « Reply #8 on: July 05, 2010, 07:53:43 AM »
            Only just come back to see your reply. Glad to see someone reacted the same way i did when i first found that little gem of a program Autohotkey is just awesme!!!  ;D
            ---------------------------------------------------------------------------
            I work at  MendMyComputer