11

How can I replace the default program providing console windows under Windows XP?

I know of alternative programs, and I have a shortcut to start cmd.exe in Console2. But now I want console applications to start in Console2 rather than the default console program, even when I have no control over the program that starts the console application. (I.e. a non-console program starts consoleapp.exe, and I can't change it to start Console2 instead, but I still want the application to be started inside a new instance of Console2.)

(Note that I want to replace the console itself, that is, the window in which console (i.e. text mode) applications run. And I must be able to run arbitrary, unmodified console applications: a substitute for a specific console program such as Cmd won't do me any good.)

EDIT: So what I'm after is a CSRSS replacement, which leads to

OT: I want to know when Microsoft is going to make a decent CSRSS replacement. Not being able to adjust the width of a "terminal" by resizing the window is a complete joke.

Go download the ISE already. (It's included in Win7/2008R2.)

But as far as I understand this ISE is an environment for Powershell, not a general console emulator.

Gilles 'SO- stop being evil'
  • 69,786
  • 21
  • 137
  • 178
  • The deficiency mentioned in your new quote does not apply to CMD when it is run inside Console2, anyway, IIRC. – paradroid Sep 30 '10 at 18:33
  • @jason404: Yes but if you double-click a batch file, for instance, it will not open in Console2. Instances like this are where you could actually need to replace the command line shell. I think it's a great question, +1. – Sasha Chedygov Sep 30 '10 at 20:09
  • May be "Attach" of std console into new tab of console emulator suit you? Manual attach, I mean. – Maximus Jul 03 '12 at 20:51
  • @Maximus I don't understand what you're refering to. By “std console”, do you mean CSRSS? Where is that “attach” thing? – Gilles 'SO- stop being evil' Jul 03 '12 at 20:59
  • ConEmu may attach any existing "real console" (CSRSS, yes) or simple GUI applications into its tab. Attach may be done manually from ConEmu interface, or by execution special command in console (if applicable). – Maximus Jul 03 '12 at 21:18
  • @Maximus I'd never heard of ConEmu before (I guess you mean [this](http://sourceforge.net/projects/conemu/))? Thanks, I'll try it out next time I'm on a Windows machine. – Gilles 'SO- stop being evil' Jul 03 '12 at 21:22
  • @Maximus If ConEmu can solve my problem, then yes, please, post an answer. It's ok to post an answer about your own product as long as your post genuinely answers the question and you disclose that you are the author (see the [faq#promotion]). – Gilles 'SO- stop being evil' Jul 03 '12 at 21:44

2 Answers2

9

I'm an author of ConEmu - Windows console emulator. One of its features is capturing to its tab existing consoles or simple GUI applications. So, after starting console program in standard console (CSRSS/ConHost), you may:

  • In the ConEmu system menu, choose "Attach..." item (Win+G by default) and choose attaching window. If ConEmu was not started, you may optionally start it without creating console/tab on startup:

    C:\Tools\ConEmu.exe /detached
    
  • Or, if applicable, run in the started console the following command (ConEmu\Attach.cmd) which initiates attaching from console side. Note, in that case, ConEmu.exe (GUI) will be started automatically, if not already exists.

    ConEmuC.exe /ATTACH /NOCMD
    
  • There is one more way. I think it doesn't match your requirements, however I'll disclose it. There is a key in the registry, which contents cmd/tcc executes after console startup. While you are starting consoleapp.exe, not cmd.exe, this miss. There is Cmd_Autorun.cmd file in ConEmu distrib to install/uninstall this command.

    [HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
    "AutoRun"="\"<Command to be executed>\"" 
    

There is a tag here, on Superuser.com

UPD. Build 120704. Alternative nonintrusive attach mode for console windows.

ConEmu attach external console dialog

UPD2. Build 121128. It is possible to intercept "creation of console window" from specified (by user) applications, for example explorer.exe,vcexpress.exe. Read more about this intrusive experimental feature.

Pang
  • 937
  • 1
  • 9
  • 12
Maximus
  • 20,637
  • 16
  • 91
  • 116
  • Looks promising, but it doesn't work for me (I suppose it might work for others). When I try to attach `consoleapp.exe`, I get the message `ConEmuC.X, PID=5656 Injecting remote into PID=5432 FAILED, code=-111:0x00000057`. Since `consoleapp.exe` is a program I'm debugging, seeing “injecting remote” makes me suspect that the technique used by ConEmu will never work for me — I can't allow “foreign” programs to perturb the program I'm debugging. – Gilles 'SO- stop being evil' Jul 04 '12 at 12:35
  • Try build 120704. May be alternative mode will work for you. – Maximus Jul 04 '12 at 21:01
  • Build 120704 with alternative mode works, thanks. If I can't replace the default console emulator, attaching to a better one after the application is started is better than nothing. [I can't figure out how do it in one key press](http://superuser.com/questions/445394/attach-a-running-console-application-to-a-new-conemu-instance), though. – Gilles 'SO- stop being evil' Jul 05 '12 at 18:09
  • @Maximus: I can't help not to commend your great work. I rarely use Windows, but am sometimes forced to, and when I am, I need Cygwin or Msys integration. While Console2 had the nicest solution that I saw so far, it was somewhat clunky. ConEmu is very nice, but I wish for 2 things: 1. it should have a better support for profiles, i.e. it should have a manager for saving/deleting custom console profiles (e.g. calling `sh` directly; 2. it should allow splitting the window in multiple vertical/horizontal tabs and recall this custom tab arrangement on restart. – axel22 Jul 13 '12 at 22:07
  • @axel22: You may post wishes to [ConEmu Issues](http://code.google.com/p/conemu-maximus5/wiki/Issues?tm=3). 1. There are profiles already. 2. In the roadmap. – Maximus Jul 13 '12 at 22:20
1

You can't. Win32 consoles always use the built-in console windows provided by CSRSS.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • Thanks, now I know what I'm after is a CSRSS replacement. – Gilles 'SO- stop being evil' Sep 30 '10 at 18:12
  • @Gilles: Good luck with that. (Actually, on Windows 7 much of its functionality has been moved into the kernel, but it still stays a "critical process", being core of Win32 subsystem and all that.) – u1686_grawity Sep 30 '10 at 18:24
  • @Gilles: Then use a different shell, as I said. The Win32 console is just the standard Windows terminal emulator. – paradroid Sep 30 '10 at 18:29
  • 1
    @jason404: And as Gilles said, it is not the _shell_ (cmd.exe) but the _console_ (terminal emulator) he's looking to replace, so that _any program_ that uses console windows would use the replacement. – u1686_grawity Sep 30 '10 at 18:58
  • 2
    Windows 7's console window implementation has been moved out of `csrss` into `conhost.exe`. Sadly, it's still the same old UI, and as far as I know, its APIs are undocumented. More at http://blogs.technet.com/b/askperf/archive/2009/10/05/windows-7-windows-server-2008-r2-console-host.aspx – ak2 Sep 30 '10 at 20:10
  • @ak2: So _that's_ why they take ages to open. – u1686_grawity Oct 01 '10 at 18:11