2017-06-27 31 views
-1

您想: [1]接受此次會議的證書 請輸入您的選擇(默認選擇是[1]):1 我必須在這裏輸入第一個數字,如何通過電源外殼完成腳本如何使用powershell keystroke發送號碼1。

+0

的可能的複製(https://stackoverflow.com/questions/ 43852056/powershell-interact-with-executables-command-line-prompts) – BenH

回答

0

Read-Host將是使用寫主機/寫輸出呈現選項信息時從控制檯執行此操作的方式。你當然需要檢查變量的內容,看看你是否得到了預期的結果。

如果你正在尋找一個簡單的是/否的答案,並與彈出窗口OK,使用.NET的MessageBox:此其中包括給你的控制能力

[System.Windows.Forms.MessageBox]::Show('message', 'titlemessage') 

有噸重載顯示的按鈕和圖標(警告,錯誤信息等)

編輯:這SO交示出了如何使用兩個COM對象和.NET對象完成的SendKeys功能:How to perform keystroke inside powershell?

$wshell = New-Object -ComObject wscript.shell; 
$wshell.AppActivate('title of the application window') 
Sleep 1 
$wshell.SendKeys(1) 

add-type -AssemblyName System.Windows.Forms 
[System.Windows.Forms.SendKeys]::SendWait(1) 

add-type -AssemblyName microsoft.VisualBasic 
add-type -AssemblyName System.Windows.Forms 

[Microsoft.VisualBasic.Interaction]::AppActivate(「Calc」) 
[System.Windows.Forms.SendKeys]::SendWait(「1{ADD}1=」) 

從:[?Powershell的 - 交互有可執行的命令行提示] https://blogs.technet.microsoft.com/heyscriptingguy/2011/01/10/provide-input-to-applications-with-powershell/

+1

我相信他並不是要求腳本提示輸入該信息,而是要求腳本將該信息輸入到可執行文件中。 – BenH

+0

啊,是的......我現在明白了。他想與提示進行交互。請參閱編輯。 – thepip3r

相關問題