如何使用“默认"启动 powershell.exePowerShell 快捷方式中的颜色? [英] How can I launch powershell.exe with the "default" colours from the PowerShell shortcut?

查看:39
本文介绍了如何使用“默认"启动 powershell.exePowerShell 快捷方式中的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您从预安装的快捷方式之一启动 PowerShell 窗口时,我会注意到它的漂亮蓝色.但是,如果您手动启动 powershell.exe,则不会显示这些颜色,而是显示黑色/白色 :(

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 :(

这是因为默认设置是在快捷方式 (.lnk) 文件上设置的:

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

我在资源管理器上下文菜单中有一个PowerShell Prompt Here"条目,我希望它使用与常用快捷方式相同的漂亮颜色启动 PowerShell;黑色很糟糕,而且有不同颜色的窗口会让人困惑(尤其是当我经常打开一些也是黑色的老式命令窗口时!).

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. 在 PowerShell 中设置颜色似乎只允许某些值(ConsoleColor 枚举),这些值都不匹配默认快捷方式上的值.
  2. 在 PS 配置文件中设置颜色只会导致之后写入的文本采用新的背景颜色.添加cls"会导致原始颜色在开始时出现令人讨厌的闪光.

是否有任何方法可以从命令行启动 PowerShell(即,我可以将其作为资源管理器上下文菜单项嵌入到注册表中),该命令行将使用与快捷方式相同的设置?

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?

推荐答案

这里有一个非常简单的方法:

Here's a really easy way:

开始 -> 运行sysdm.cpl" -> 高级 -> 环境变量

Start -> run "sysdm.cpl" -> advanced -> Environment Variables

向下滚动系统变量,双击PATHEXT

Scroll Down through system variables, double click PATHEXT

添加.LNK;如下图:

Add .LNK; as depicted below:

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

3.从运行提示输入powershell"现在将显示默认的控制台颜色/配置.

您可以根据自己的喜好进一步自定义 C:\Windows\System32 中的 .lnk.

3. Typing "powershell" from a run prompt will now bring up the default console color/configuration.

You can further customize the .lnk in C:\Windows\System32 to your liking.

请注意,这只会起作用,因为您已将 .lnk 添加到可接受的扩展名列表中,并且默认情况下 c:\windows\system32 是搜索路径(PATH 系统变量)中的第一项.

Please note that this will only work because you have added the .lnk to the list of acceptable extensions AND c:\windows\system32 is the first item in the search path (PATH system variable) by default.

如果通过 cmd.exe 启动,这不会自定义控制台.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\PowerShellHere\command]
@="C:\\WINDOWS\\system32\\cmd.exe /c start powershell -NoExit \"cd '%1';(get-host).ui.rawui.windowtitle = 'Oompa Loompa'\""

[HKEY_CLASSES_ROOT\Directory\shell\PowerShellHere\command]
@="C:\\WINDOWS\\system32\\cmd.exe /c start powershell -NoExit \"cd '%1';(get-host).ui.rawui.windowtitle = 'Oompa Loompa'\""

我正在使用 cmd.exe 调用start",它将启动 powershell.lnk 并将当前工作目录作为参数传递.似乎还不能从地址栏中工作.我应该在 45 分钟前回家,但你的问题解决起来很有趣!:)

I am using cmd.exe to call "start" which will launch the powershell.lnk and pass the current working directory as an argument. Doesn't seem to work from the address bar yet. I should have gone home 45mins ago, but your problem was fun to solve! :)

奖励积分:您可以将发送到 Powershell 的命令线程化.因此,如果您想修改 Powershell 控制台的标题属性:

Bonus Points: You can thread the commands sent to Powershell. So, if you are looking to modify the Powershell console's title attribute:

\"cd '%1';(get-host).ui.rawui.windowtitle = 'Oompa Loompa'"

只需在命令之间添加一个分号.

Simply add a semicolon between commands.

快乐炮击

这篇关于如何使用“默认"启动 powershell.exePowerShell 快捷方式中的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆