PowerShell发送击键,例如F5打开申请后

时间:2013-06-17 07:28:47

标签: powershell-v2.0

我正在使用PowerShell打开一个应用程序,然后发送按键F5,即“正在运行”,就像有人按下F5键盘启动快捷键一样。

然而,[System.Windows.Forms.SendKeys] :: SendWait(“{F5}”)无法正常工作,我不知道它是否是正确的句子?

Start-Process "C:\Users\minnie\Documents\Ixia\IxLoad\Repository\HTTP Concurrent conns port1n2.rxf"

Start-Sleep -s 50

[System.Windows.Forms.SendKeys]::SendWait("{F5}")

exit

1 个答案:

答案 0 :(得分:1)

这当然不是最好的方法,但您可以尝试以下方式:

[System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
start-process notepad
$p=get-process | where {$_.name -eq "notepad"}
[Microsoft.VisualBasic.Interaction]::AppActivate($p.ID)
[System.Windows.Forms.SendKeys]::SendWait("~Name:{TAB}$env:UserName~")
# [System.Windows.Forms.SendKeys]::SendWait("{F5}{ENTER}")

您还应该查看该扩展程序: http://wasp.codeplex.com/