Reputation: 135
I would like to use regular expression or wild card in tasklist
I have imagename going to be different for every build like AB1adf.exe, AB2dfas.exe, AG3dfas.exe ect
I have tried below but did not work..
tasklist /FI "IMAGENAME eq AB%.exe" | find /i "AB%.exe"
tasklist /FI "IMAGENAME eq AB*.exe" | find /i "AB*.exe"
Upvotes: 2
Views: 1474
Reputation: 57252
find does not support wild cards. You have two options wmic
and findstr:
tasklist | findstr /i /r "ab.*exe"
or with wmic and wql (which allows richer expressions) (for batch file you need to double the %
):
wmic process where "Caption like 'AB%exe'" get Caption,ProcessId,Commandline /format:value
Upvotes: 0
Reputation: 175766
The extension breaks the wild card:
C:\>tasklist /FI "IMAGENAME eq chr*.exe"
ERROR: The search filter cannot be recognized.
Lose it:
C:\>tasklist /FI "IMAGENAME eq chr*"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
chrome.exe 4376 Console 1 313,076 K
chrome.exe 4384 Console 1 4,328 K
chrome.exe 4548 Console 1 94,260 K
Upvotes: 3