title: Disabling Alt+F4 in a Powershell form
body: <p>I've written a powershell script which displays a form using <code>System.Windows.Forms</code>.  I've already disabled the control box and all other ways that this form can be closed via the mouse.  But I can't find a way of preventing the form closing by pressing <kbd>Alt</kbd>+<kbd>F4</kbd>.  </p>
  
  <p>i.e. Code snippet looks like this:</p>
  
  <pre><code>[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
  [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
  $objForm = New-Object System.Windows.Forms.Form 
  $objForm.Text = "Restart Required"
  $objForm.Size = New-Object System.Drawing.Size(400,300) 
  $objForm.StartPosition = "CenterScreen"
  $objForm.KeyPreview = $True
  $objForm.Topmost = $True
  $objForm.MinimizeBox = $false
  $objForm.MaximizeBox = $false
  $objForm.FormBorderStyle = "Fixed3d" 
  $objForm.ControlBox = $false
  $objForm.ShowInTaskbar = $false
  $objForm.Add_Shown({$objForm.Activate()})
  [void] $objForm.ShowDialog()
  </code></pre>
  
  <p>Looking at <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing.aspx?cs-save-lang=1&amp;cs-lang=csharp#code-snippet-1" rel="nofollow">MSDN</a>, there are articles about overriding the <code>FormClosing</code> eventhandler in VB, C#, etc and .  But I'm not sure how to implement similar logic into Powershell (if it's at all possible).</p>