The application acts as an Alarm, Reminder, Mailer and Command Line executor all
packed into one. You can set the timer to start an alarm after some specified
time. You can also add a Message to pop up at that time to remind of something
to be done. Or you could execute any commands from the command prompt or even
better you can compose a mail that will be sent at the predetermined time. Now
in case you want to send mail alone or execute a command without using the
Timer then that too is possible.
It all started as a simple Scheduler and then I started adding on these extra
features when I came across difficulties faced by others on the Net with regard
- Making Sounds in C#
- Sending attachment along with mail
- Hiding an application while it is in execution mode
- Getting a Command Prompt
Using the code
First we'll start off with the code related to the Timer: The implementation for
this application has made some use of the Timer alarm code taken from the
article Use a timer to
create a simple alarm application by Andrew Boisen. My complements to
you, Andrew Boisen. So you can refer to that article for detailed comments and
the whole code that he has used. The additional input made was for the sound by
Kernel32.dll.You will have to use the
Add this to your variable declarations.
public static extern bool Beep(int freq, int duration);
Now that all that we need to make the sound is
For Sending Mail you need to add a reference to your project to
we need to add the
The code snippet shown below is self documentary. You can place this code in
your button click event also.
MailMessage msgMail = new MailMessage();
msgMail.From = txtFrom.Text; msgMail.To = txtTo.Text; msgMail.Cc = txtCC.Text; msgMail.Bcc = txtBCC.Text; msgMail.Subject = txtSubject.Text; msgMail.Body = txtMessage.Text; if (txtAttachment.Text.Length > 0)
strSentMail = "Message Sent to " + txtTo.Text;
strSentMail+= " Carbon Copy Sent to " + txtCC.Text;
strSentMail+= " Blind Carbon Copy Sent to " + txtBCC.Text;
To get the command prompt to execute your commands and exit is done by the code
snippet below. But first we need to use the
Then you can add this code snippet to get your command prompt.
process1= new System.Diagnostics.Process();
process1.EnableRaisingEvents = false;
strCmdLine = "/C " + txtCmd.Text.Trim();
Points of Interest
The only nutty thing that I did was to have the mailing program and the command
line executor added into the timer. So when the predetermined time was over you
could send mail and execute commands. And you could execute the commands for
any number of times depending on the number you inputted in the textbox with
instances. (These options do work independent of the timer also.)
Its so easy to make a simple application really "un-simple??".
Let me end with this quote - "If confusion is the first step to knowledge, I must
be a genius."