[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 857
  • Last Modified:

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.).
0
dbbishop
Asked:
dbbishop
  • 3
  • 2
2 Solutions
 
vb_jonasCommented:
Hi! Here's a nice article to get you started:

http://www.devcity.net/Articles/74/1/servicecontroller.aspx

0
 
vb_jonasCommented:
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
Next
0
 
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.
0
 
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?
0
 
vb_jonasCommented:
Hi!
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now