6

I am wondering if it is possible to change CMD's window title to /?

I've tried using ^/?, ^/^?, and "/?" but none of them seem to work.

Anyone got any suggestions?

Thanks

5
  • title "/?" works for me. Edit: oops just realized that it displays "/?" with quotes
    – phuclv
    Mar 2, 2017 at 3:17
  • 1
    in PowerShell [System.Console]::Title = "/?" will just work, but if we call powershell from cmd it'll start a subshell so we can't keep the old environment
    – phuclv
    Mar 2, 2017 at 3:48
  • 1
    I somewhat found a workaround. If you type start "/?" it opens another CMD window with the correct title of /?. Unfortunately, this needs to open another window, and it can't just be changed on the fly. Mar 2, 2017 at 3:55
  • Not work with title = ^/?, title = "/?"... either
    – phuclv
    Mar 2, 2017 at 4:12
  • 2
    wow.. after all these years knowing batch thinking i can do absolutely anything i cannot get it to work.. closest i have got was //? or '/?' Mar 2, 2017 at 6:57

2 Answers 2

5

It's possible with adding some invisible characters.
The idea is taken from @npocmaka SO: How can I set set a title that start with coma,semicolon or equal sign?
The problem of a title with a starting comma it can be solved also with a LF character, but in your case the LF doesn't help anywhere in the string.

@echo off

(set LF=^
%=empty=%
)

::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
1
@ECHO OFF
if "%~1"=="_SO42546112_" (
    shift
) else (
    start "/?" cmd /D /K ""%~f0" "_SO42546112_""
    exit
)

To launch a new CMD command prompt with /? window title, double click above .bat script.


To run a .bat script with /? window title, use above concept e.g. as follows:

@ECHO OFF
SETLOCAL EnableExtensions

rem self wrapper - start
if "%~1"=="_SO42546112_" (
    shift
) else (
    start "/?" cmd /D /C ""%~f0" "_SO42546112_" %*"
    exit /B
    rem  ↑↑  omit the `/B` switch to close calling `cmd` window
)
rem self wrapper - end

rem check whether the self wrapper works - start   
echo 1st "%~1"
echo 2nd "%~2"
echo 3rd "%~3"
echo all %*
pause
rem check whether the self wrapper works - end

rem original script continues here:  
1
  • Nice idea to use start instead of title to change the title
    – jeb
    Mar 3, 2017 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.