A development example of C # PowerShell 2.0 module, and using of the
.NET Class Notify Icon. The module creates a notification balloon and a icon in system tray.

Demo and use of the module BalloonNotification can be seen in the video: http://www.youtube.com/watch?feature=player_detailpage&v=IXEhP-02zNE

It's also written a blog about the module, but this is only written in Norwegian: http://blog.silihagen.net

 

C#
Edit|Remove
using System; 
using System.Diagnostics; 
using System.Management.Automation; 
using System.Drawing; 
using System.Windows.Forms; 
 
namespace BalloonNotification 
{ 
    [Cmdlet("Show""Notification")] 
    public sealed class NotifyIconpop : PSCmdlet 
    { 
        private string iconType; 
        private string message; 
        private string title; 
        private string notifiaction; 
        private System.Windows.Forms.NotifyIcon notify = new System.Windows.Forms.NotifyIcon(); 
                 
        public ContextMenu contextMenu1 = new ContextMenu(); 
        public MenuItem menuItem1 = new System.Windows.Forms.MenuItem(); 
 
        // Message 
        [ValidateNotNullOrEmpty] 
        [Parameter(Mandatory = true, Position = 0)] 
        public string Message 
        { 
            get 
            { 
                return this.message; 
            } 
            set 
            { 
                this.message = value; 
            } 
        } 
 
        // Title 
        [ValidateNotNullOrEmpty] 
        [Parameter(Position = 1)] 
        public string Title 
        { 
            get 
            { 
                return this.title; 
            } 
            set 
            { 
                this.title = value; 
            } 
        } 
 
        // Action variable 
        [ValidateNotNullOrEmpty] 
        [Parameter(Mandatory = false, Position = 2)] 
        public string NotifiAction 
        { 
            get 
            { 
                return this.notifiaction; 
            } 
            set 
            { 
                this.notifiaction = value; 
            } 
        } 
 
        // Icon Type 
        [ValidateSet("Information""Warning""Error""Exclamation""Hand""Shield""Question")] 
        [Parameter(Mandatory = false, Position = 3)] 
        public string IconType 
        { 
            get 
            { 
                return this.iconType; 
            } 
            set 
            { 
                this.iconType = value; 
            } 
        } 
               
        // NotificationIcon Balloon start initilization  
        [STAThread] 
        protected override void ProcessRecord() 
        { 
            base.ProcessRecord(); 
            Process thisProcess = Process.GetCurrentProcess(); 
          
            // Icon menu 
            contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { menuItem1 }); 
            menuItem1.Index = 0; 
            menuItem1.Text = "E&xit"; 
            menuItem1.Click += new System.EventHandler(menuItem1_Click); 
           
            // Balloon and icon settings 
            notify.Icon = typeof(SystemIcons).GetProperty(this.iconType).GetValue((object)null, (object[])nullas Icon; 
            notify.BalloonTipIcon = ToolTipIcon.None; 
            notify.BalloonTipText = this.Message; 
            notify.BalloonTipTitle = this.Title; 
            notify.ContextMenu = contextMenu1; 
            notify.Visible = true 
            notify.ShowBalloonTip(40); 
             
            // If balloon clicked or closed 
            notify.BalloonTipClicked += (sender, e) => 
            { 
                // If no balloon action added 
                if (string.IsNullOrEmpty(this.NotifiAction) == true) 
                { 
                    CleanUp(notify); 
                } 
                else 
                { 
                    System.Diagnostics.Process.Start(this.NotifiAction); 
                    CleanUp(notify); 
                } 
            }; 
            notify.MouseMove += (sender, e) => 
            { 
                notify.ShowBalloonTip(40); 
                notify.Visible = true; 
            };       
        } 
 
        // Clean up 
        static void CleanUp(System.Windows.Forms.NotifyIcon c) 
        { 
            c.Visible = false; 
            c.Dispose(); 
            Application.Exit(); 
        } 
         
        // Exit from menu 
        private void menuItem1_Click(object Sender, EventArgs e) 
        { 
            CleanUp(notify); 
        }           
    } 
}
 
PowerShell
Edit|Remove
Import-module BalloonNotification 
Show-Notification -Message "Demo text" -Title "Hi" -NotifiAction "Http://cv.silihagen.net" -IconType Information