The purpose of this application is to create a simple Notification application (ala Instant Messenger). Upon receiving an alert, the application will display some "toast" in the lower right-hand corner of your desktop. The alert will display a message and will execute an action when clicked on.
The idea for this application came as a result of trying to come up with something "cool" for sale's demos. Customers love demos that illustrate "real-time" notification of business events. While this functionality does exists via several Microsoft products (i.e. SQL Server Notification, MSN Alerts and Real-Time Communication Server), the infrastructure/cost to configure/support/program these applications can be quite overwhelming. Often, sales demos are done on standalone laptop machines that are not always connected to a network. This simple application demonstrates the value of real-time communication without having to be a technology guru to get it up and running.
The use case scenario described above is also the reason MyAlerts is written completely in script code. It makes it easy to do modifications without having to recompile/redeploy code. Also, I am a strong advocate of keeping things as simple as possible so that semi-technical people can understand how the application works and make improvements and/or modifications.
I have included two versions of Alert Controllers:
- AlertController.hta is based on creating alerts using pop-up "toast" similar to that used in popular Instant Messenging products.
- AgentAlertController.hta uses Microsoft Agent Technology combined with a Speech Engine to create a more interactive alert.
Using the code
To install this application,
- Extract the contents of the zip file to c:\MyAlerts
- Execute AlertController.hta or AgentAlertController.hta (app will be minimized on startup)
- Execute one of the samples in the samples subdirectory (i.e. CreateAlert.hta)
An optional step that I usually perform is to add a shortcut to [Agent]AlertController.hta to my Window's Startup Group so that the application restarts on a reboot.
Alerts are triggered when a file is written to the \MyAlerts\queue subdirectory. The structure of the file is quite simple. It is a text file containing a text string in the following format:
Text To Display|URL to Execute|Voice to announce alert in
Basically, 3 text strings delimited by the |(pipe) character. For example, a file with the following contents ...
will display an alert announced in a female voice with a UK accent with the text message "Hello Microsoft". Note that the "voice" parameter is only relevant to AlertController.hta. The voice for AgentAlertController.hta is dependant on which speech engine you have installed. When clicked upon the alert will take you to the Microsoft Web Site.
Voice Options include
To trigger an alert, all your application has to do is write a text file with the above structure to the \MyAlerts\queue subdirectory. For example, from your C# .NET app, you can do something like:
TextWriter output = File.AppendText("c:\\MyAlerts\\queue\\" +
The file MyAlertsWS.asmx in the samples subdirectory contains a .Net WebService that triggers notifications. Simply copy this file to c:\inetpub\wwwroot and execute it via
Or from a Window's VBScript file, you can do something like
Set myTypeLib = CreateObject("Scriptlet.Typelib")
GUID = left(trim(myTypeLib.guid),38)
szFileName="c:\MyAlerts\queue\" & GUID & ".txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile(szFileName, True)
Or if you prefer JScript, you can do something like
var myTypeLib = new ActiveXObject("Scriptlet.Typelib");
var GUID = new String(myTypeLib.guid).substr(0,38);
var szFileName="c:\\MyAlerts\\queue\\" + GUID + ".txt"
var fso = new ActiveXObject("Scripting.FileSystemObject")
var tf = fso.CreateTextFile(szFileName, true);
You can even Trigger Alerts directly from SQL Server by using a SQL Trigger to execute the stored procedure located in samples\CreateAlert.sql. For example, assuming you have created the sp_CreateAlert stored procedure in the NorthWind Database, you can do something like the following:
CREATE TRIGGER DataChanged ON Customers
FOR INSERT, UPDATE, DELETE
AS EXEC sp_CreateAlert 'Customer Changed','http://www.microsoft.com',
Points of Interest
MyAlerts supports skinning (i.e. themes) and by default shows a different skin whenever an alert occurs. To change this behavior, simply edit the file ShowAlert.hta in notepad and modify the following lines of code:
var enableRandomSkin = true;
For example, the following screenshot shows an alternative skin:
NOTE: AgentAlertController.hta makes use of Microsoft Agent ActiveX Controls as well as Speech Engines. If AgentAlertController.hta does not work or generates errors, you may have to download the required components at Microsoft Agent Downloads
NOTE: All images uses for skinning were obtained via Wincustomize.com and are copyright via their respective owners.
- Modified October 30, 2003
- Added AgentAlertController.hta to demonstrate use of Microsoft Agent Technology
- Added StockAlertController.hta to demonstrate how to trigger an alert based on a Web Service call.