我正在尝试使用PowerShell启动一个程序,我可以这样做。但该程序会弹出一个用于登录用户ID和密码的登录窗口。
PowerShell是否有办法在字段{TAB}中输入用户ID信息,然后输入密码并输入{ENTER}以便程序可以登录AS400服务器?
我似乎无法找到PowerShell填充对话框的方法。这是我到目前为止所尝试的内容:
[System.Diagnostics.Process]::Start("C:\BPCS.WS").WaitForExit()
$app = get-process | where {$_.mainwindowtitle -match "User"}
$processID = 0
foreach ($a in $app) {
if ($a.id -gt $processID)
{
$processID = $a.id
}
}
start-sleep -Milliseconds 500
答案 0 :(得分:1)
不确定它是否可行,但值得尝试使用SendKeys。 作为一个起点:
[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
#start your app as in your question
#then give the focus to it
[Microsoft.VisualBasic.Interaction]::AppActivate("ws") #or user? you'll have to test this
[System.Windows.Forms.SendKeys]::Sendwait("$username");
[System.Windows.Forms.SendKeys]::Sendwait("{TAB}");
[System.Windows.Forms.SendKeys]::Sendwait("$password");
[System.Windows.Forms.SendKeys]::Sendwait("{ENTER}");