如何通过PowerShell脚本以编程方式输入击键?
Write-Host -ForegroundColor Green 'Loading...'
Function EnterKey {
[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
#Where I want to get "|" keystroke programmatically
[System.Windows.Forms.SendKeys]::SendWait("{|}")
}
Function StartUp {
Write-Host "Environment"
$exe = ([IO.Path]::Combine("D:\7ZipApp\7ZipApp\7ZipApp\bin\Debug","7ZipApp.exe"))
& $exe 3 # argument 3 = 'Run local Sync'
EnterKey
Read-Host -Prompt $exe.ToString()
}
StartUp发布于 2016-01-06 00:24:40
Write-Host -ForegroundColor Green 'Loading...'
function StartUp {
Write-Host 'Environment'
$exe = Join-Path "D:\7ZipApp\7ZipApp\7ZipApp\bin\Debug" "7ZipApp.exe"
#& $exe 3 # argument 3 = 'Run local Sync'
start $exe -ArgumentList 3
Write-Host 'Type {|} to continue'
while ((Read-Host) -ne '{|}') {}
Read-Host -Prompt $exe.ToString()
}
StartUp发布于 2016-01-06 05:48:58
我不得不在这里跟随人群(从评论中):
我会放弃你的方法。太麻烦了。
我的问题是你为什么要做这件事
因此,正确的解决方案是让7zipapp.exe的作者修复程序,使其停止这样做,或者添加一个命令行参数来阻止这种行为。
也就是说,如果你想要一个完全的hack,并且这个程序只需要一次输入,最后大概可以,那么下面的方法看起来是可行的。我会谨慎地使用,也许永远不会使用它,而是修复程序,但在我的测试中,这是有效的。
PowerShell:
$exe = 'C:\ConsoleApplication2\bin\Debug\ConsoleApplication2.exe'
'\r\n' | & $exe烦人的C#程序:
using static System.Console;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
WriteLine("I will force you to hit Enter to exit.");
ReadLine();
}
}
}https://stackoverflow.com/questions/34616028
复制相似问题