Skip to content

Instantly share code, notes, and snippets.

function Confirm-Host {
<#
.SYNOPSIS
Prompts the user to OK or Cancel an operation via the host.
.DESCRIPTION
Prompts the user to OK an operation by hitting ENTER or cancel
it by hitting ESC.
.EXAMPLE
if(Confirm-Host) { ... }
.OUTPUTS
param(
[int]$Delay = 0
)
$Win32 = Add-Type -Name WinAPICall -Namespace SystemParametersInfo -PassThru -MemberDefinition @'
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni);
'@
if($Win32::SystemParametersInfo(0x17,$delay,$null,0)) {
Write-Host "Keyboard delay changed to: $delay"
} else {