I have included two batch files within this project- one to install the service, and another to UNinstall it. To install the newly created service, you must use the. Now, simply Build TestCSWinWatcherService (from the Build menu), and all necessary installer files will be created within the project directory. This will enable the service to be run as a local system account. I left the StartType property as Manual.įor the serviceProcessInstaller, set the Account property to LocalSystem. On the properties for serviceInstaller1, set the ServiceName to TestCSWinWatcherService. If these components are NOT located in the toolbox, simply right-click on the toolbox, and then "Choose Items." to add them: Now, we need to add two new components to the class- a ServiceInstaller and ServiceProcessInstaller installer. (I left this file named as Installer1.cs.) In order to accomplish this, we must first add an InstallerClass file to our project ("Project->Add New Item."): The last item at hand for completion of this project is to create the windows installer class to allow the project to be compiled as a Windows service. This will be the actual name that shows up in the "Services" window in the Control Panel, once the service is installed. Lastly, go into the properties for Service1.cs (in design), and change the ServiceName property to something meaningful. System.IO.File.Copy(e.FullPath, " C:\\temp\\archive\\" + e.Name) For example, if you want to copy a file that is dropped into your defined "watch" directory, you would use something like this within the FSWatcherTest_Created() event: code here for newly renamed file or directoryĪdd whatever code is necessary within each event, and it will get executed when the event is fired. / private void FSWatcherTest_Renamed( object sender, / /// Event occurs when the a File or Directory is renamed code here for newly deleted file or directory / private void FSWatcherTest_Deleted( object sender, / /// Event occurs when the a File or Directory is deleted code here for newly created file or directory / private void FSWatcherTest_Created( object sender, / /// Event occurs when the a File or Directory is created code here for newly changed file or directory / private void FSWatcherTest_Changed( object sender, */ /// /// Event occurs when the contents of a File or Directory are changed Within the configuration which we've just added, we will need to add an " appSettings" section, where we'll define our directory path: We will use this to define a directory (path) to "watch": Now, add a new Application Configuration File to the project. Add a reference to " System.Configuration" by right-clicking on the project, then "Add Reference.": Next, an appropriate reference must be added to the project as we will be using an application configuration file. I named this sample solution TestCSWinWatcherService and optionally, chose to create a directory for the solution file. Using the codeįirst, open Visual Studio.NET and create a new Windows Service project for C#: You must have a machine running Microsoft. This article will briefly explain how to set up a simple "File Watcher/ Directory Watcher" application to run as a Windows Service using Visual Studio 2005.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |