Question

I have a question about a batch process that I haven't been able to find anywhere yet. I need to create a batch file that determines whether a task under the applications in Task Manager is running and take a certain action. I found a lot of answers on how to tell whether a process is running, but this case is a little trickier. The applications task contains the text

Administrator: [YODA][oo.server.start]

but the process in the Task Manager is listed only as cmd.exe which is unfortunately not specific enough to know whether it's the task I want. I've tried using psexec, but none of the information it's given me has been helpful. And as far as I'm aware, there's no way to find the tasks running (not the processes) in cmd. Any thoughts?

Was it helpful?

Solution

How about PowerShell?

Get-Process | Select-Object MainWindowTitle

Use it in batch something like this:

for /f "delims=" %%A in ('"PowerShell Get-Process ^| Select-Object MainWindowTitle ^| Select-String YODA"') do echo(%%A

Example Output:

@{MainWindowTitle=Administrator:  YODA}

No PowerShell...

If you know the exact title of the application you can use tasklist

tasklist /FI "WINDOWTITLE eq Administrator:  YODA"

Note that there are two spaces between Administrator: and YODA because cmd.exe has that quirk.

Example Output:

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
cmd.exe                       5996 Console                    1      1,024 K

OTHER TIPS

You can use the title command in the batch file to set the title and then use tasklist to determine the window with that title.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top