【问题标题】:How to launch PowerShell (not a script) from the command line如何从命令行启动 PowerShell(不是脚本)
【发布时间】:2011-12-29 15:53:02
【问题描述】:

我是 PowerShell 的新手,并且正在为我认为应该是一个简单的操作而苦苦挣扎——我正在尝试从命令行启动一个 PowesShell 窗口。

如果我启动一个命令行实例并输入powershellstart powershell,我会在命令行界面中获得一个PowerShell 实例,即典型的黑色背景和白色文本。我想要的是典型的 PowerShell 界面启动——蓝色背景和白色文本?我正在运行安装了 PowerShell 2.0 的 Windows XP。

【问题讨论】:

    标签: powershell powershell-2.0


    【解决方案1】:

    如果您在 Windows 资源管理器中转到 C:\Windows\system32\Windowspowershell\v1.0(以及 x64 计算机上的 C:\Windows\syswow64\Windowspowershell\v1.0)并双击 powershell.exe,您将看到它打开了黑色背景的 PowerShell。从开始菜单打开时,PowerShell 控制台显示为蓝色,因为可以独立于默认属性设置 powershell.exe 快​​捷方式的控制台属性。

    要设置默认选项、字体、颜色和布局,请打开 PowerShell 控制台,键入 Alt-Space,然后选择默认菜单选项。

    从 cmd.exe 运行 start powershell 应该会使用您的默认设置启动一个新控制台。

    【讨论】:

      【解决方案2】:

      设置默认的控制台颜色和字体:

      http://poshcode.org/2220
      来自 Windows PowerShell Cookbook (O'Reilly)
      李·霍姆斯 (http://www.leeholmes.com/guide)

      Set-StrictMode -Version Latest
      
      Push-Location
      Set-Location HKCU:\Console
      New-Item '.\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe'
      Set-Location '.\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe'
      
      New-ItemProperty . ColorTable00 -type DWORD -value 0x00562401
      New-ItemProperty . ColorTable07 -type DWORD -value 0x00f0edee
      New-ItemProperty . FaceName -type STRING -value "Lucida Console"
      New-ItemProperty . FontFamily -type DWORD -value 0x00000036
      New-ItemProperty . FontSize -type DWORD -value 0x000c0000
      New-ItemProperty . FontWeight -type DWORD -value 0x00000190
      New-ItemProperty . HistoryNoDup -type DWORD -value 0x00000000
      New-ItemProperty . QuickEdit -type DWORD -value 0x00000001
      New-ItemProperty . ScreenBufferSize -type DWORD -value 0x0bb80078
      New-ItemProperty . WindowSize -type DWORD -value 0x00320078
      Pop-Location
      

      【讨论】:

        【解决方案3】:

        颜色和窗口大小由快捷方式 LNK 文件定义。我想我找到了一种可以满足您需求的方法,试试这个:

        explorer.exe "Windows PowerShell.lnk"
        

        LNK 文件位于所有用户开始菜单中,该菜单位于不同的位置,具体取决于您使用的是 XP 还是 Windows 7。在 7 中,LNK 文件位于此处:

        C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows PowerShell
        

        【讨论】:

        • 太棒了!如果您右键单击并选择属性,您可以看到 .lnk 是如何存储所有属性的。
        猜你喜欢
        • 2018-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-13
        • 1970-01-01
        • 2019-07-17
        • 2011-06-11
        • 1970-01-01
        相关资源
        最近更新 更多