1

许多应用程序都有相关的帮助,您可以通过按 F1 来调用这些帮助。
什么 PowerShell 命令会启动应用程序并打开帮助?
我想到的应用程序是 Powershell ISE、Visual Studio、Microsoft Office 等。
这有标准机制吗?

谢谢。

4

1 回答 1

2

没有一个命令可以执行此操作,但您可以通过以下方式执行此操作:

  1. 启动应用程序。
  2. 激活它的窗口
  3. 将 F1 键发送给它。

就是这样:

启动应用程序:

Start-Process -FilePath C:\The\Path\To\Program.exe 

等待它:

$WindowTitle = "The App You're Waiting For"
while ($true) {
    Start-Sleep -Seconds 1
    $p = get-process | ? {$_.MainWindowTitle -match $WindowTitle}
    if ($p) {break}
}

激活窗口:

[void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
[Microsoft.VisualBasic.Interaction]::AppActivate($WindowTitle)

发送 F1 键:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("{F1}")
于 2012-02-29T06:36:57.583 回答