How can I launch powershell.exe with the “default”

2019-01-22 02:16发布

I'm attached to the nice blue colour of the PowerShell window when you launch it from one of the pre-installed shortcuts. However, if you manually launch powershell.exe, you don't get these colours, you get black/white :(

This is because the default settings are set on the shortcut (.lnk) file:

PowerShell shortcut colour settings

I've got a "PowerShell Prompt Here" entry in Explorer context menu, and I'd like it to launch PowerShell using the same nice colours as the usual shortcut; black sucks, and it's confusing to have different coloured windows (especially when I have some old-school command windows open frequently that are also black!).

I've found two problems with trying to set this so far:

  1. Setting the colour from within PowerShell seems to only allow certain values (ConsoleColor enum), none of which match the one on the default shortcut.
  2. Setting the colour within the PS Profile causes only text written afterwards to honour the new background colour. Adding "cls" causes a nasty flash of the original colour as it starts.

Is there any way to launch PowerShell from a command line (ie. that I can embed in the registry as an Explorer context menu item) that will use the same settings as the shortcut?

8条回答
家丑人穷心不美
2楼-- · 2019-01-22 02:43

I found it very useful to use concfg tool and scoop to install colors and fonts for Powershell:

  1. Install scoop:

    iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
    
  2. Install concfg:

    scoop install concfg
    
  3. Install Solarized theme:

    concfg import solarized
    

That's it, thanks to the authors!

查看更多
别忘想泡老子
3楼-- · 2019-01-22 02:53

Edit your profile script (pointed to by $profile) and set the desired colors yourself:

# set regular console colors
[console]::backgroundcolor = "darkmagenta"
[console]::foregroundcolor = "darkyellow"

# set special colors

$p = $host.privatedata

$p.ErrorForegroundColor    = "Red"
$p.ErrorBackgroundColor    = "Black"
$p.WarningForegroundColor  = "Yellow"
$p.WarningBackgroundColor  = "Black"
$p.DebugForegroundColor    = "Yellow"
$p.DebugBackgroundColor    = "Black"
$p.VerboseForegroundColor  = "Yellow"
$p.VerboseBackgroundColor  = "Black"
$p.ProgressForegroundColor = "Yellow"
$p.ProgressBackgroundColor = "DarkCyan"

# clear screen
clear-host
查看更多
做个烂人
4楼-- · 2019-01-22 02:57

This was my solution (setting the colors in a script that launches as system). May be more than you need (see my own answer):

https://superuser.com/questions/891519/using-psexec-to-launch-powershell-session-as-system-with-specific-window-attribu

查看更多
聊天终结者
5楼-- · 2019-01-22 02:59
  1. Run regedit command to open registry editor
  2. Track down HKEY_CURRENT_USER > CONSOLE and Backup entire folder by exporting just in case
  3. Delete the folder

Restart your Powershell, the color scheme must have reset to defaults.

Note: If you have any other settings related to PowerShell (or Command Prompt, Git Bash etc) which you might want to keep, please further explore Console Folder to delete appropriate keys

查看更多
放我归山
6楼-- · 2019-01-22 03:00

Click the system menu (PowerShell icon in the top-left of the window) and click Defaults. You can change the default colors here and it will be respected by the PowerShell Prompt Here command.

From: https://superuser.com/a/523017/109736

查看更多
Melony?
7楼-- · 2019-01-22 03:03

The correct way to do this is with the Registry

cd hkcu:/console
$0 = '%systemroot%_system32_windowspowershell_v1.0_powershell.exe'
ni $0 -f
sp $0 ColorTable00 0x00562401
sp $0 ColorTable07 0x00f0edee
查看更多
登录 后发表回答