So erhalten Sie den Fenstertitel in Windows von der Shell

Ich kann den Titel über die windows-shell mit dem Befehl title some string aber wie kann ich den Titel eines Prozesses erhalten?

Ich habe den Befehl tasklist /v ausprobiert, aber mein Titel ist sehr, sehr lang, deshalb erhalte ich nur einen Teiltitel. Außerdem habe ich über das WMIC-Dienstprogramm nachgedacht, kann aber das gewünschte Flag nicht finden.

Author: Sathyajith Bhat, 2012-01-15

3 answers

Das folgende Skript zeigt, dass tasklist /v /FO:CSV lange Fenstertitel nicht schneidet und unabhängig voneinander zwei Aufgaben löst:

  • Teil 1 zeigt alle nützlichen Fenstertitel zusammen mit Bildnamen und PIDs im csv - Format an; findstr wird verwendet, um die Ausgabe auf wirklich nützliche Titel einzugrenzen.
  • Teil 2 zeigt PID und Titel des Eingabeaufforderungsfensters an, aus dem das Skript ausgeführt wurde (mein eigenes cmd).

Skript:

@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

Ausgabe:

==> 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!!!

==> .\SU\378790.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!!! - .\SU\378790.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!!!

==>

Ressourcen (erforderliche Lesung):

 6
Author: JosefZ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-09-01 03:47:29

AutoHotkey kann Ihnen dabei helfen. Schreiben wir ein Skript, das den Prozess und die Titel aller geöffneten Fenster an stdout ausgibt:

WinGet, windows, list

Loop, %windows%
{
    id := windows%A_Index%
    WinGet, process, ProcessName, ahk_id %id%
    WinGetTitle, title, ahk_id %id%
    FileAppend, %process% %title%`n, *
}

ExitApp

Kompilieren Sie das Skript, um ein tragbares zu erhalten.exe - .

Jetzt können wir Folgendes über die Windows-Befehlszeile ausführen:

MyScript.exe | more

Beispiel:

Abbildung

 5
Author: iglvzx,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2012-01-16 05:27:18

Die Shell ist Powershell:

Get-Process | Where-Object {$_.mainWindowTitle} | Format-Table Id, Name, mainWindowtitle -AutoSize

Und für den Titel des ausgewählten Prozesses:

(Get-Process -id 8748 -ErrorAction SilentlyContinue).MainWindowTitle
 2
Author: Krzysztof Gapski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-09-09 07:30:07