How can I set a title that starts with comma, semi

2019-01-28 06:07发布

问题:

Obviously it is possible to set title that contains cmd's standard delimiters but through TITLE command looks impossible to set a title that starts with a delimiter.

It is possible to create a new instance of CMD with such title:

start "==" cmd.exe

but not possible for the same instance.

It is possible also with .NET and Console.Title property but when it's called from batch file the tile lasts as long as the compiled exe runs:

@if (@X)==(@Y) @end /* JScript comment
@echo off
setlocal

for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d  /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do (
   set "jsc=%%v"
)

if not defined jsc (
        echo !!! Installation of .NET framework needed !!!
        pause
        exit /b 3
)

rem echo %jsc%
::if not exist "%~n0.exe" (
        del /q /f %~n0.exe
        call "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0"
::)

call %~n0.exe %*

endlocal & exit  /b %errorlevel%


*/

import System;

var arguments:String[] = Environment.GetCommandLineArgs();
//Console.WriteLine(Console.Title);
if (arguments.length>0){
         Console.Title=arguments[1];
}
//Console.WriteLine(Console.Title); 

(Probably is possible through code injection)

Is there a windows 'native' way?

回答1:

With Win7 x64, I can produce it when a linefeed is in front of the problematic characters.

@echo off
setlocal EnableDelayedExpansion
set LF=^



title !LF!,bc

In Win7 there seems no difference in the height or position of the title when LF is used.

Tested with

cmd /V:on
@for /L %n in (1 1 1111) do @(title !LF!=Hello& title +Hello)

But the current program is shown for the time it's running in the title, so the TITLE command itself produces a flicker.



回答2:

I found another way:

title ^A,string

where ^A is produced by entering 0 1 while holding down the ALT-key ( <pressALT><0><1><releaseALT> ).

You can get it into a file with echo ^A>>batch.bat and then moving it to the correct position with notepad (it's not shown in notepad, like a whitespace; broader than a space, but not as broad as a TAB)



回答3:

The LF is the answer to the question , but there's also a workaround. I think I've checked all the ASCII characters and looks like FS and GS characters are not displayed in title of command prompt (here's an example with FS):

@echo off 
setlocal 
::dbenham's hexprint was used here 
::http://www.dostips.com/forum/viewtopic.php?p=23888 
::Define a Linefeed variable 
set LF=^ 


::above 2 blank lines are critical - do not remove. 

::Create a FS variable 
call :hexprint "0x1C" FS 

title %FS%=;= 
exit /b 

:hexPrint  string  [rtnVar] 
  for /f eol^=^%LF%%LF%^ delims^= %%A in ( 
    'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"' 
  ) do if "%~2" neq "" (set %~2=%%A) else echo(%%A 
exit /b

But this is not a 'perfect' solution as AppActivate or Tasklist command will detect the FS and GS characters (no such problem with LF). Also SOH character can be used but it is displayed as space.

FS can be produced also with ctrl+]

GS with ctrl+\

SOH with ctrl+A