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

  • SEARCH
  • Home
  • 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 8389045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:36:57+00:00 2026-06-09T18:36:57+00:00

I don’t think this is possible, but I’d like to be able to do

  • 0

I don’t think this is possible, but I’d like to be able to do this, or possibly use an alternative method…

I have a batch file;

for /f "usebackq tokens=*" %%a in (`wmic process get description, commandline`) do (
*Some Code*
)

I need to be able to take the two answers from each line, and use them individually (basically, use the description to check if a process is running, then after I’ve killed the process and done some file clean-up work, reload the original process including any command line parameters.

One example of the output for a process I may need to end/re-open might be;

"C:\some folder\some other folder\some_application" -cmd_parameter                process_name.exe

Note that the descrption is clearly defined by multiple spaces..

So is there a way of saying

for /f "tokens=* delims=  "    <--(The delims is TWO spaces, not space OR space)

Another way that may be better could be to replcae all instances of multiple spaces with a special character (i.e. one that is never used in a proces or path), and then use that as my delimeter… Though I don’t know if that is even possible..

I’m also open to any alternative methods, as long as I can get the process name (to check against a pre-defined list of processes, and the full path to the exe, plus any command line paramteres given.

Thanks all

  • 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-09T18:36:58+00:00Added an answer on June 9, 2026 at 6:36 pm

    In direct answer to you question: No, you cannot specify 2 spaces as a delimiter. You can use SET search and replace to change 2 spaces into some unique character, but determining a unique character that will never appear in your description or command line is easier said then done.

    A better alternative is to change the output format of WMIC to LIST – one value per line in the form of propertyName=Value. Each propery value can be stored in a variable, and then when the last property for a process is recorded you can take action using the variable values. WMIC output uses Unicode, and that results in a CarriageReturn character being appended to the end of each variable assignment. The CarriageReturn must be stripped to get the correct results.

    @echo off
    setlocal
    for /f "tokens=1* delims==" %%A in ('"wmic process get description, commandline /format:list"') do (
      if "%%A"=="CommandLine" (
        set "cmd=%%B"
      ) else if "%%A"=="Description" (
        set "desc=%%B"
        setlocal enableDelayedExpansion
        set "desc=!desc:~0,-1!"
        set "cmd=!cmd:~0,-1!"
        echo(
        echo Do whatever you need to do with the description and command line.
        echo description=!desc!
        echo command line=!cmd!
        endlocal
      )
    )
    

    There are a few things you need to be careful of.

    1) You could have multiple processes for the same image name. If you kill a process via the image name (description), then you will delete all of them. If you also restart it it based on the command line, then it will be killed again when the next process with the same name is killed. It is probably better to kill the process via the process ID.

    2) If you know the image name (description) of the process, then you can restrict your output using the WMIC WHERE clause.

    3) The command line reported by WMIC is not always reliable. The process is able to modify the value that is reported as the command line.

    Here is a solution that retrieves the process ID and command line for a specific description.
    EDIT – I fixed the code below

    @echo off
    setlocal
    for /f "tokens=1* delims==" %%A in ('"wmic process where description='MyApp.exe' get processId, commandline /format:list"') do (
      if "%%A"=="CommandLine" (
        set "cmd=%%B"
      ) else if "%%A"=="ProcessId" (
        set "id=%%B"
        setlocal enableDelayedExpansion
        set "id=!id:~0,-1!"
        set "cmd=!cmd:~0,-1!"
        echo(
        echo Do whatever you need to do with the process id and command line.
        echo process Id=!id!
        echo command line=!cmd!
        endlocal
      )
    )
    

    Note – the WMIC WHERE clause uses SQL syntax. It can be made complex using AND and OR conditions, and it supports the LIKE operator using % and _ as wildcards. I believe the entire expression needs to be enclosed in double quotes when it becomes complex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if this is possible, but I have some code like this: val
Don't ask me why but i can't use this method because I need to
Don't think my virtualhost is working correctly. This is what I have inside of
Don't know if I'm over-thinking this or not.. but I'm trying to be able
Don't know why but I can't find a solution to this. I have 3
don't know better title for this, but here's my code. I have class user
Don't ask me how but I'm in a situation where I have DCPs published
I don't know why, but this code worked for me a month ago... maybe
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if anyone can help me with this or if it's even possible.

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.