Using FOR command to extract PID from TASKLIST Put this in a .bat file, and you could use it like that: BAT_FILE.bat for /F "tokens=2,* delims=, " %%i IN ('tasklist ^| findstr %1') DO %%i %2 This is useful when writing an injector, and looking to inject to a specific process by its name, for example: Replace MY_COMMAND with something like inject.exe, which will inject depending on a provided file path BAT_FILE.bat notepad.exe my_library.dll