Disclaimer: I have absolutely no coding experience in any language.
I need to create a script that can find the PID for a process, of which there will be multiple running, and then create a process dump for each PID. Procdump doesn't allow the process name to be used if more then one is running, so my goal is to to have the PID found for the process and then be set to variables for later commands.
Here is a .bat I have made:
for /F "tokens=2" %%K in ('
tasklist /FI "ImageName eq T.exe" /FI "Status eq Running" /FO LIST ^| findstr /B "PID:"
') do (
set "X= %%K"
)
c:\Users\Public\Documents\Procdump\procdump.exe -ma %X%
pause
I am able to get the last PID set and used in a command, but I can't figure out how to get the first two.
This may seem like a lot of work for one go, but the later goal is for this to run every 2 and 5 hours for 24 hours. I have been able to get that to work so for now i just need to solve the PID problem. In hindsight, maybe powershell would have been a better choice, but i feel like i got close so I want to to see this route through.
There could be three processes max. I was thinking it would look something like this:
for /F "tokens=2" %%K in ('
tasklist /FI "ImageName eq T.exe" /FI "Status eq Running" /FO LIST ^| findstr /B "PID:"
') do (
set "X= %%K"
set "Y=???"
set "Z=???"
)
c:\Users\Public\Documents\Procdump\procdump.exe -ma %X%
c:\Users\Public\Documents\Procdump\procdump.exe -ma %Y%
c:\Users\Public\Documents\Procdump\procdump.exe -ma %Z%
pause
If you need to execute procdump.exe nice per item, simply move it into the for /F loop with -ma %%K as the parameters