# BAT Cheatsheet



# Using FOR command to extract PID from TASKLIST

Put this in a .bat file, and you could use it like that:  
BAT\_FILE.bat &lt;PROCESS\_NAME&gt; &lt;COMMAND&gt;

> for /F "tokens=2,\* delims=, " %%i IN ('tasklist ^| findstr %1') DO &lt;MY\_COMMAND&gt; %%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