Create a Windows Service for Dummies

I want to buld a Windows Service. It will run on a machine, and will contain a FileSystemWatcher to monitor a directory. When a new file arrives, I want to send an email with that file as an attachment, then move the file to a different directory (upon success). I am basically an application developer, and although I am fairly proficient with prior versions of VB, am still getting my feet wet with .NET.

I've added a new project, and made it a Windows service. I've added a reference to Outlook and I've added a FileSystemWatcher to the design page and set its properties. One thing I want to do, and don't have an idea how to is to add an icon in the taskbar notification area when the service starts. Right-clicking on the icon would open a popup menu with an option to stop the service and also have an indication that Outlook is running (perhaps 'Outlook' as an item with a checkmark next to it if it is running). I would like to possibly change the appearance of the icon if an error occurred while the service is running (unable to send file, error occurred moving the file after sending the message, etc.).
LVL 15
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi! Here's a nice article to get you started:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
To control your service:
' need a reference to System.ServiceProcess

Imports System.ServiceProcess

Dim scServices() As ServiceController
 scServices = ServiceController.GetServices()

 Dim scFindService As ServiceController
 For Each scFindService In scServices
 If scFindService.ServiceName = "My service name" Then
  scFindService.Stop() ' or .Start() or .Status to get the current status
 End If
dbbishopAuthor Commented:
Well, I am definately delving into new territory here and obviously there is no simple cut-and-paste solution, but I am hoping this can help me get started.

This particular project was pushed to a lower priority after I asked the question, so it may be awhile before I get back to it, but I am going to PAQ it for now and work my way through it when I get a chance. Thanks for hopefully getting me pointed in the right direction.
dbbishopAuthor Commented:
If you don't mind me asking one quick question. I'm still not deep into theis, but doing a little research. Unless I am mistaken, I actually need two projects; one is the service itself, the second is a Windows application (which the link above references) that actually allows me to control the service. Is that correct?

If I am reading stuff properly, I would install the service (in my case have StartType = Automatic), and then in my Startup execute the 'controller' program?
If you would stop/stop the service you would need to create another app to do it, I would prefer doing it that way. But it would also be possible to have the service running all the time, and let itself controll when to start/stop the FileSystemWatcher.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.