我做了一個程序,打開某個程序,然後Ctrl + C它在x時間後。發送密鑰到PowerShell中打開的窗口
我現在使用這個[System.Windows.Forms.SendKeys]::SendWait("^{c}")
。 這是針對某個窗口還是隨機發送到當前窗口?
如何將其更改爲某個窗口?
這是我的代碼:
Write-Host "Safe Botting V0.1"
Write-Host "Initializing..."
Start-Sleep -s 3
Write-Host "Program started successfully with no errors."
While($true)
{
Write-Host "Starting bot..."
Start-Sleep -s 3
Start-Process -FilePath E:\Documents\bot.exe
Write-Host "Bot started successfully"
$rnd = Get-Random -Minimum 1800 -Maximum 10800
Write-Host "The bot will run for:"
Write-Host $rnd
Start-Sleep -s $rnd
Write-Host "Bot will now stop!"
[System.Windows.Forms.SendKeys]::SendWait("^{c}")
Write-Host "Bot terminated"
Write-Host "Starting cooldown time"
$rnb = Get-Random -Minimum 14400 -Maximum 28800
Write-Host "The bot will cooldown for"
Write-host $rnb
Start-Sleep -s $rnb
Write-Host "Cooldown Finished, Restarting"
Start-Sleep -s 5
}
你究竟想在這裏實現什麼?這聽起來像[XY問題](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem);我懷疑問題有一個更清晰的解決方案,例如使用'Taskkill'命令。另外,請在你的帖子中包含你的實際代碼。 –
正在嘗試運行的程序必須由Ctrl + C停止,否則下次將無法加載。 –
那麼['Stop-Process'](https://technet.microsoft.com/en-us/library/ee177004.aspx)命令怎麼樣? –