OS: Windows XP, Windows 7 64bit.
We have some fairly hefty cmd scripts that are used for some daily build processes. These scripts spawn numerous other (windowed) processes. There is one controlling cmd script, a small simple script, which starts the main cmd script. The purpose of the small controlling script is to clean up in situations where the main script or any of its children fail. This is accomplished fairly easily: the main script and all its children have window titles which begin with a unique identifier. When the controlling script determines that the main script and all its children should have completed, it uses tasklist to find windows of any hung processes, via:
tasklist.exe /FI "WINDOWTITLE eq UniqueIdentifier*"
This all worked very nicely in XP. Now enter Windows7 64-bit. Here, if the main .cmd script or any other .cmd shell window attempts to sets its window title via
title UniqueIdentifier Followed By Descriptive Text
Windows7 64-bit kindly prepends other text to the title (specifically, "Administrator: " or similar). The prepended text cannot be relied upon. So now we want to use
tasklist.exe /FI "WINDOWTITLE eq *UniqueIdentifier*"
but THIS FAILS with the error message "The search filter cannot be recognized". Going the route of using our UniqueIdentifier as a post-fix does not work: the command
tasklist.exe /FI "WINDOWTITLE eq *UniqueIdentifier"
also results in the same error message. It seems that Microsoft's notion of "wildcard" in a filter does not extend beyond having a "*" as the terminal character. Ouch.
DOES ANYONE HAVE ANY WORK-AROUNDS? Pslist does not seem to allow filtering with window title.
You can use the /V option to include the window title in the output and then pipe the result to FIND (or FINDSTR) to filter the result.
tasklist /v | find "UniqueIdentifier"
tasklist /v | findstr /c:"UniqueIdentifier"
If using FINDSTR then I recommend using the /C option so that you can include spaces in the search string.
You might want to use the /I
option if you need to do a case insensitive search.