replacing the default console emulator under Windows XP

11

6

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'

Posted 2010-09-29T21:28:38.533

Reputation: 58 319

The deficiency mentioned in your new quote does not apply to CMD when it is run inside Console2, anyway, IIRC. – paradroid – 2010-09-30T18:33:25.263

@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 – 2010-09-30T20:09:40.400

May be "Attach" of std console into new tab of console emulator suit you? Manual attach, I mean. – Maximus – 2012-07-03T20:51:39.873

@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' – 2012-07-03T20:59:57.600

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 – 2012-07-03T21:18:21.960

@Maximus I'd never heard of ConEmu before (I guess you mean this)? Thanks, I'll try it out next time I'm on a Windows machine.

– Gilles 'SO- stop being evil' – 2012-07-03T21:22:08.853

@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' – 2012-07-03T21:44:46.390

Answers

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.

Maximus

Posted 2010-09-29T21:28:38.533

Reputation: 19 395

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' – 2012-07-04T12:35:53.887

Try build 120704. May be alternative mode will work for you. – Maximus – 2012-07-04T21:01:41.493

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, though.

– Gilles 'SO- stop being evil' – 2012-07-05T18:09:29.753

@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 – 2012-07-13T22:07:22.130

@axel22: You may post wishes to ConEmu Issues. 1. There are profiles already. 2. In the roadmap.

– Maximus – 2012-07-13T22:20:42.770

1

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

user1686

Posted 2010-09-29T21:28:38.533

Reputation: 283 655

Thanks, now I know what I'm after is a CSRSS replacement. – Gilles 'SO- stop being evil' – 2010-09-30T18:12:38.800

@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.) – user1686 – 2010-09-30T18:24:04.013

@Gilles: Then use a different shell, as I said. The Win32 console is just the standard Windows terminal emulator. – paradroid – 2010-09-30T18:29:51.070

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. – user1686 – 2010-09-30T18:58:22.740

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 – 2010-09-30T20:10:59.097

@ak2: So that's why they take ages to open. – user1686 – 2010-10-01T18:11:03.410