links:
– http://superuser.com/questions/769244/how-to-test-empty-parameter-in-a-for-f-loop
– http://serverfault.com/questions/126502/how-to-get-own-process-pid-from-the-command-prompt-in-windows
summary:
– WMIC is like database query tool on windows tasks
– common problems parsing of queried results:
= name of queried column that is not needed (skip=1)
= query back own WMIC command (NOT name like wmic)
= extra CRLF end of result set (^| findstr “.”)
= passing in env variable to query (%%%ENVVAR%%%)
for /f "skip=1 tokens=1" %%a in ('wmic process where "name like '%%%ENVVAR%%%.exe'" get processid ^| findstr "."') do ( taskkill /f /t /pid %%a )
– taskkill options,
= /f forced
= /t treekill (need elevated privilege)
Advertisements