How can I launch powershell.exe with the “default” colours from the PowerShell shortcut?

前端 未结 9 1365
野趣味
野趣味 2020-12-13 06:56

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, yo

9条回答
  •  误落风尘
    2020-12-13 07:11

    Based on @rex-hardin excellent answer, I improved the regedit content here to add an icon, and use the PowerShell native arguments to start in the right path.

    The context-menu is enabled when right-clicking on a directory background, and when right-clicking directly on a directory icon.

    Of course, we also run a console with blue background exactly like the default one.

    1. Add ".LNK" extension to %PATHEXT% environment variable

    This allows system to execute files with .lnk extension (hidden extension for shortcuts)

    2. Copy the default PowerShell shortcut link to system32 as powershell file

    This allows the powershell command to launch our shortcut from system32 folder (which is in %PATH%)

    Use explorer (copy+rename) or the command-line below:

    Copy-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows PowerShell\Windows PowerShell.lnk" "C:\Windows\System32\powershell.lnk"
    

    3. Add code below to a powershell_here.reg file and execute it.

    powershell_here.reg

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\directory\background\shell\PowerShell]
    @="PowerShell Here"
    "Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
    
    [HKEY_CLASSES_ROOT\directory\background\shell\PowerShell\command]
    @="cmd.exe /c start powershell -NoExit -NoProfile -Command Set-Location -LiteralPath '%V'"
    
    [HKEY_CLASSES_ROOT\directory\shell\PowerShell]
    @="PowerShell here"
    "Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
    
    [HKEY_CLASSES_ROOT\directory\shell\PowerShell\command]
    @="cmd.exe /c start powershell -NoExit -NoProfile -Command Set-Location -LiteralPath '%L'"
    

提交回复
热议问题