O script abaixo mostra que tasklist /v /FO:CSV
não trunca títulos de janela longa e independentemente resolve duas tarefas:
-
Parte 1 exibe todos os títulos de janelas úteis juntamente com nomes de imagens e PIDs em
csv
format; findstr
é usado para restringir a saída a títulos úteis realmente .
-
Parte 2 exibe o PID e o título da janela de prompt de comando na qual o script foi executado ( my own
cmd
).
Script :
@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
rem Part 1: ALL USEFUL WINDOW TITLES
echo(
set "_myExcludes=^\"conhost ^\"dwm ^\"nvxdsync ^\"nvvsvc ^\"dllhost ^\"taskhostex"
for /F "tokens=1,2,8,* delims=," %%G in ('
tasklist /V /fo:csv ^| findstr /V "%_myExcludes%"
') do (
if NOT "%%~J"=="N/A" echo %%G,%%~H,%%J
)
rem Part 2: MY OWN cmd WINDOW TITLE
echo(
set "_myTitleTail= - %~0"
for /F "tokens=1,2,8,* delims=," %%G in ('
tasklist /V /fo:csv ^| findstr /I /C:"%_myTitleTail%"
') do (
set "_myTitleBatch=%%~J"
set "_myCmdPIDno=%%~H"
)
call set "_myCmdTitle=%%_myTitleBatch:%_myTitleTail%=%%"
echo _myCmdPIDno=%_myCmdPIDno%
SETLOCAL EnableDelayedExpansion
echo _myCmdTitle=!_myCmdTitle!
ENDLOCAL
Saída :
==> TITLE ...but my title is very, very long, that's why I receive only partial title. Also
I was thinking about wmic utility, but can't find desired flag!!!
==> .\SU8790.bat
"Image Name",PID,"Window Title"
"VDeck.exe",4032,"VIA HD Audio Deck"
"chrome.exe",5760,"How to get window title in windows from shell - Super User - Google Chrom
e"
"powershell_ise.exe",5568,"Windows PowerShell ISE"
"cmd.exe",4980,"...but my title is very, very long, that's why I receive only partial title.
Also I was thinking about wmic utility, but can't find desired flag!!! - .\SU8790.bat"
"PSPad.exe",5108,"378790.bat"
"cmd.exe",3888,"d:\bat"
"cmd.exe",5648,"Administrator: Command Prompt"
_myCmdPIDno=4980
_myCmdTitle=...but my title is very, very long, that's why I receive only partial title. Als
o I was thinking about wmic utility, but can't find desired flag!!!
==>
Recursos (leitura obrigatória):