How can I get the value of the current window's
title, set like this:
TITLE Here Are The New Contents
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
In cmd.exe (usual command line prompt):
Set window's title:
title "Your New Title"
Get window's title: I didn't found anything useful to do such thing, However if you have some knowledge with C# or Visual Basic, you can develop a little program that will look in opened windows to find your command line and return the title for you. (using the PID of parent process (your cmd.exe))
In Powershell: (things are easy here)
Set window's title:
[system.console]::title = "Your New Title"
Get window's title:
$myTitleVar = [system.console]::title
or you can directly:
From a batch file, calling PowerShell is easiest (though it won't be fast):
powershell -noprofile -c "[Console]::Title.Replace(' - '+[Environment]::CommandLine,'')"
The above takes advantage of the fact that
- <command-line> to the window title while executing an external program.
If your batch file is directly invoked and the window title was set beforehand, the title will include your batch file's own invocation as a suffix (e.g,
Command Prompt - some.cmd)
However, if your batch file is called from another batch file, and it is the latter that sets the title, your batch file's invocation will not that title.
In the former case, use the following variant if you want to remove the own-invocation suffix from the title:
powershell -noprofile -c "[Console]::Title.Replace(' - '+[Environment]::CommandLine,'') -replace '(.+) - .+'"
@echo off setlocal rem # Assign a custom title. title This ^& That rem # Retrieve the current title. for /f "usebackq delims=" %%t in (`powershell -noprofile -c "[Console]::Title.Replace(' - '+[Environment]::CommandLine,'')"`) do set thisTitle=%%t echo This window's title: "%thisTitle%"
The above yields:
This window's title: "This & That"