Is there a way to catch ctrl-c and ask the user to confirm?
问题 Powershell scripts can easily be terminated by the user pressing ctrl-c. Is there a way for a Powershell script to catch ctrl-c and ask the user to confirm whether he really wanted to terminate the script? 回答1: Checkout this post on the MSDN forums. [console]::TreatControlCAsInput = $true while ($true) { write-host "Processing..." if ([console]::KeyAvailable) { $key = [system.console]::readkey($true) if (($key.modifiers -band [consolemodifiers]"control") -and ($key.key -eq "C")) { Add-Type