Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:54:44+00:00 2026-06-08T17:54:44+00:00

I need to check for certain processes (its a list of 20ish processes, so

  • 0

I need to check for certain processes (its a list of 20ish processes, so wont list them all), and record which ones are running. Then I need to kill them, run some other code, and finally reopen them… The code will only run successfully if all the processes have been ended.

I’d welcome any suggestions, or just someone to explain why my code doesn’t work.

What I’ve been doing, is using tasklist to check for each process, and write the results to a file, then I’m trying to remove the lines of the file where the process is not running (i.e. I get an “INFO:…” message)

I know that I have done something similar before, where I’ve taken each line of a file one at a time (in a for loop), replaced a string of text within it, and sent the edited line to another file (which is probably not the most efficient way of doing it, but it worked).

For some reason, I can’t replicate it now…

The code I’ve got (whch is failing) is

SETLOCAL ENABLEDELAYEDEXPANSION 
cd\
for /f "tokens=* delims= " %%a in (somefile.txt) do (
set q=INFO: No tasks are running which match the specified criteria.
set r=%%a
set s=!r:%q%=!
echo %s% >>test.txt
)

If anyone knows of a better way to do what I need, I’m happy to change my plan, but it does need to be done through batch (CMD), or I’d be happy with some one fixing the above code at least.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:54:46+00:00Added an answer on June 8, 2026 at 5:54 pm

    Try this code. Though I’m not sure if the output file matches the one you want. Make sure to surround the parameter with double quotes if it contains any space.

    taskchk.cmd:

    @echo off
    SETLOCAL ENABLEDELAYEDEXPANSION
    if "%1" == "" (
      echo Please specify criteria.
      echo e.g.: taskchk myprocess.exe
      goto :eof
    )
    cd\
    type nul>test.txt
    set found=0
    for /f "tokens=*" %%a in ('tasklist /nh') do (
      for /f "tokens=1" %%b in ("%%a") do (
        if /i "%%b" == "%~1" (
         set found=1
        ) else (
         echo %%a>>test.txt
        )
      )
    )
    if %found% == 0 echo INFO: No tasks are running which match the specified criteria.>>test.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to check a certain selection of checkboxes using JavaScript. All these checkboxes
I need to check some settings for all users on Windows clients in the
I need to check if a certain property exists within a class. Please refer
I need to check if certain keyspace exists in Cassandra database. I need to
I've got a few Unix shell scripts where I need to check that certain
I'm doing some validation where I need to check for certain combinations between two
I need to check if a certain android device has a hardware button in
I need to read a text based log file to check for certain contents
I need to check for a condition on each page I visit on the
I need to check for duplicates before saving to the database in the create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.