Powershell equivalent of vbscript msgbox

Author Message
TomRiddle

  • Total Posts : 620
  • Scores: 12
  • Reward points : 0
  • Joined: 2/7/2008
  • Location: Australia
  • Status: offline
Powershell equivalent of vbscript msgbox Sunday, June 20, 2010 10:42 PM (permalink)
0
Hi,
 
The closest equivalent I can find to VBScript's msgbox function is this.
 
$objShell = new-object -comobject wscript.shell
$return = $objShell.popup("This is a popup message",10,"Popup Title",33)
if ($return -eq 1)
{
   "Do something"
}
 
Am I missing the point of PowerShell wanting the old msgbox function? The above code does the trick for me, I want the script to stop and flash a question on the screen asking a yes no type answer. Maybe someone knows of a more PowerShell native type method for this task?
 
Cheers
-join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:Powershell equivalent of vbscript msgbox Monday, June 21, 2010 12:02 AM (permalink)
    0
    Well, if you want to keep it in the .Net family:

    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [System.Windows.Forms.MessageBox]::Show("Hello")

    The [System.Windows.Forms.MessageBox] can be a little tedious to type out every time so if you plan to use it often do this:

    $msg = [System.Windows.Forms.MessageBox]
    $msg::Show("Hello")
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      TomRiddle

      • Total Posts : 620
      • Scores: 12
      • Reward points : 0
      • Joined: 2/7/2008
      • Location: Australia
      • Status: offline
      Re:Powershell equivalent of vbscript msgbox Tuesday, June 22, 2010 1:06 AM (permalink)
      0
      good one ebgreen,

      I have only just started to scratch the surface of dotnet so this side is all a wonder to me at the moment.

      Here are another couple I found
      [System.Reflection.Assembly]::`
      LoadWithPartialName("Microsoft.VisualBasic")
      [Microsoft.VisualBasic.Interaction]::`
      MsgBox("Do you agree?", "YesNoCancel,Question", "Question")

       
      and
       
      #System Tray Balloon Popup
           #The popup mesage
           $Message="This is a message shown in system tray balloon popup"

       
           #popup title
           $Title="Attention $env:username"

       
           # Valid Message types "Info" "Error" "Warning" "None"
           $MessageType="Info"
          
           # The number of seconds to display the message.
           [int]$duration=60

          #load Windows Forms and drawing assemblies
          [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
          [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null

       
          #define an icon image pulled from PowerShell.exe
          $icon=[system.drawing.icon]::ExtractAssociatedIcon((join-path $pshome powershell.exe))

          $notify = new-object system.windows.forms.notifyicon
          $notify.icon = $icon
          $notify.visible = $True

       
          #define the tool tip icon based on the message type
          switch ($messagetype) {
           "Error" { $messageIcon=[system.windows.forms.tooltipicon]::Error}
           "Info" {$messageIcon=[system.windows.forms.tooltipicon]::Info}
           "Warning" {$messageIcon=[system.windows.forms.tooltipicon]::Warning}
           Default {$messageIcon=[system.windows.forms.tooltipicon]::None}
          }

          $notify.showballoontip($duration,$Title,$message,$MessageIcon)
       
       
       
       
      <message edited by TomRiddle on Tuesday, June 22, 2010 1:10 AM>
      -join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9