Friday, 30 December 2011

Show-MessageBox.ps1

  1. <#
  2. .SYNOPSIS
  3.     This script displays a message box and then processes it
  4. .DESCRIPTION
  5.     This script firsts creates a wscript.shell object and
  6.     invokes the popup method to display a message. The script
  7.     then processes the response to the geroup (timeout, yes, no).
  8. .NOTES
  9.     File Name : Show-MessageBox.ps1
  10.     Author : Thomas Lee - tfl@psp.co.uk
  11.     Requires : PowerShell Version 2.0
  12. .LINK
  13.     This script posted to:
  14.         http://www.pshscripts.blogspot.com
  15.     MSDN sample posted tot:
  16.         http://msdn.microsoft.com/en-us/library/x83z1d9f%28VS.84%29.aspx
  17. .EXAMPLE
  18.     Left as an exercise to the reader!
  19. #>
  20. # Create the shell object
  21. $WshShell = New-Object -Com Wscript.Shell
  22. # Call the Popup method with a 7 second timeout.
  23. $Btn = $WshShell.Popup("Do you feel alright?", 7, "Question:", 0x4 + 0x20)
  24. # Process the response
  25. switch ($Btn) {
  26. # Yes button pressed.
  27. 6 {"Glad to hear you feel alright."}
  28. # No button pressed.
  29. 7 {"Hope you're feeling better soon."}
  30. # Timed out.
  31. -1 {"Is there anybody out there?"}
  32. }

No comments: