是否可以要求 Powershell 在 Windows 终端而不是新窗口中启动进程

2024-05-13

如果我在 Windows 终端 PowerShell 选项卡中运行:

start-process Powershell -Verb runas

它将创建一个新窗口。有没有办法在 Windows 终端中创建选项卡?


您必须使用 Windows 终端 CLI,wt.exe https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments,作为目标可执行文件Start-Process https://learn.microsoft.com/powershell/module/microsoft.powershell.management/start-process,并将其传递给 PowerShell CLI (powershell.exe https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe对于 Windows PowerShell,pwsh.exe https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pwsh对于 PowerShell (Core) 7+) 作为其参数;例如,与powershell.exe:

Start-Process -Verb RunAs wt.exe powershell.exe

请注意,如果使用 PowerShell 作为您的defaultWindows 终端配置文件,您无需指定参数wt.exe at all.

如果您有为 PowerShell 定义的 Windows 终端配置文件(至少对于 Windows PowerShell,默认情况下应该是这样),您可以通过以下方式请求它:name or GUID,通过-p选项。配置文件name必须完整指定,并具有定义的确切大小写(否则将被忽略并使用默认配置文件);例如。:

Start-Process -Verb RunAs wt.exe '-p "Windows PowerShell"'

Note:

  • The first提升的 Windows 终端进程总是以新窗户.

  • 如果至少一个此类进程已存在,您可以请求打开其他提升的进程:tabs在那扇窗户里-w 0作为第一个选项;例如。:

    Start-Process -Verb RunAs wt.exe '-w 0 -p "Windows PowerShell"'
    
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

是否可以要求 Powershell 在 Windows 终端而不是新窗口中启动进程 的相关文章

随机推荐