4

Good morning,
This is not a duplicate of questions like this one: I'm not looking to open the command prompt and to replace the text of the prompt by something else:
I have just downloaded conEmu, a console emulator, and I would like to replace the command prompt program (cmd.exe) by that one.

Hereby some history: I have an application that opens a command prompt, writes some things to that prompt, and also writes those same things to a logfile. In case something goes wrong, I can either read it from the command prompt or from the logfile.
Now this is the situation I'm facing: the application starts, opens the command prompt, writes some stuff and closes. While closing, also the command prompt gets closed.

I know from previous experience that this can be handled, replacing cmd.exe by a more persistent commandline tool (like conEmu, the one I've just downloaded).
Point is: I don't know how I should configure my Windows-10 machine in order to open conEmu instead of cmd.exe.

Does anybody know?
Thanks in advance

7
  • 2
    First I would rename conEmu to cmd.exe and place it in an empty directory. Then I would write a cmd script that 1. Modifies PATH by adding the directory with conEmu cmd.exe first 2. Starts the program that uses cmd.exe If the program doesn't specify an absolute path to cmd.exe it should start conEmu.
    – Robert
    Commented Mar 2, 2022 at 8:51
  • 2
    There's a setting in ConEmu that controls this. @SaaranshGarg There are only a handful of config files within %WinDir% that are user customizable and outside of those, a user should never modify anything within %WinDir%, as it's not meant to be user-modifiable and any changes to system files will be reverted once Sfc /ScanNow is run
    – JW0914
    Commented Mar 2, 2022 at 8:56
  • 3
    @SaaranshGarg Deleting/replacing something in Windows\System32 folder is always a bad idea and should only be used as a last resort.
    – Robert
    Commented Mar 2, 2022 at 8:57
  • 3
    Is this article helpful? conemu.github.io/en/DefaultTerminal.html Commented Mar 2, 2022 at 8:57
  • 1
    Considering Windows doesn't really cater for replacing cmd.exe without risking breaking something, what exactly are you do you want to achieve that would require this? You could also call upon conEmu, and then have whichever script or program you want to run, be run from there.
    – MiG
    Commented Mar 2, 2022 at 9:48

1 Answer 1

3

When installing ConEmu, the user is usually looking to replace the cmd and powershell terminals as the default terminal for both (possibly others):

  • You may find useful this export of the heavily customized config file I use, which has the options below enabled
    (Settings → Import... → Save settings)

  1. Open Settings: WinKey+Alt+P
  2. GeneralInject ConEmuHk.dll into processes, started in ConEmu tabs
  3. IntegrationDefault Term → Tick boxes:
    1. Force ConEmu as default terminal for console applications
    2. Register on OS startup
    3. Aggressive Mode
    4. Optional:
      1. Use existing ConEmu window if available
      2. List of hooked executables or window class names
        (Often this isn't needed, however if the application's console window doesn't open within ConEmu, add the application's executable)
  4. Save Settings

Since PowerShell has its own color scheme, it often doesn't look quite right in a terminal if not customized, especially if wanting the same background color regardless of command output, so I recommend also adding this to the PowerShell profile(s) used:

#

#===========================================================
        ##::[[--- Powershell PS1 Profile ---]]::##
#===========================================================

  # $env:UserProfile\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
  # %UserProfile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
  
# ANSI:
  $ESC                            = [char]27

# Colors
#-----------------------------------------------------------
$PD                               = $($Host.PrivateData)

$Host.UI.RawUI.BackgroundColor    = ($bckgrnd = 'Black')
$Host.UI.RawUI.ForegroundColor    = 'Gray'

$PD.ErrorForegroundColor          = 'Red'
$PD.ErrorBackgroundColor          = $bckgrnd

$PD.WarningForegroundColor        = 'Magenta'
$PD.WarningBackgroundColor        = $bckgrnd

$PD.DebugForegroundColor          = 'Yellow'
$PD.DebugBackgroundColor          = $bckgrnd

$PD.VerboseForegroundColor        = 'Green'
$PD.VerboseBackgroundColor        = $bckgrnd

$PD.ProgressForegroundColor       = 'Yellow'
$PD.ProgressBackgroundColor       = $bckgrnd


# Terminal
#-----------------------------------------------------------
Function set-prompt {
  Param (
    [Parameter(Position=0)]
    [ValidateSet("Default")]
    $Action
  )

  switch ($Action) {
    "Default" {
      Function global:prompt {
        if (test-path variable:/PSDebugContext) { '[DBG]: ' }
          write-host " "
          write-host ("$ESC[48;2;40;40;40m$ESC[38;2;170;210;0m$(Get-Location) $ESC[0m $ESC[0m")

        if ( $host.UI.RawUI.WindowTitle -match "Administrator" ) {
          $Host.UI.RawUI.ForegroundColor = 'Red'
          $(if ($nestedpromptlevel -ge 1) {
            write-host ('PS $$ ') -ForegroundColor Red -NoNewLine
          } else {
            write-host ('PS $ ') -ForegroundColor Red -NoNewLine
          })
        } else {
          $(if ($nestedpromptlevel -ge 1) {
            write-host ('PS $$ ') -ForegroundColor Blue -NoNewLine
          } else {
            write-host ('PS $ ') -ForegroundColor Blue -NoNewLine
          })
        }
        return " "
      }
    }
  }
}

set-prompt Default
  • Lines 10 - 33: Specifies formatting character and prompt colors
  • Lines 36 - 72: Specifies prompt layout, with different colors for regular and Admin prompts
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .