473,378 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

filesystemwatcher service

I created a service to watch the c: drive for the creation of exe's and write an event. The problem is anytime I create several vbs files as a test and then delete them, explorer.exe crashes. I think it has something to do with the fact that new files are created in the recycle bin upon deletion. Here is my code

Imports System.ServiceProces
Imports System.I

Public Class FSWatche
Inherits System.ServiceProcess.ServiceBas

' Path for the file wathcer to watch. The D: drive is the FTP server driv
Private Path As String = "c:\

Protected Overrides Sub OnStart(ByVal args() As String
' Add code here to start your service. This method should set thing
' in motion so your service can do its work
' Tr
Dim watcher As New FileSystemWatche
watcher.Path = Pat
watcher.IncludeSubdirectories = Tru
'watcher.InternalBufferSize = 819
watcher.NotifyFilter = (NotifyFilters.LastAccess Or
NotifyFilters.LastWrite Or
NotifyFilters.FileName

watcher.Filter = "*.exe

' Add event handlers

AddHandler watcher.Created, AddressOf OnChange

' Begin watching
watcher.EnableRaisingEvents = Tru

End Su

Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs
' Specify what is done when a file is changed, created, or deleted
'Select Case Tru
' Case LCase(Left(e.FullPath, 11) = "c:\recycled"
' Exit Su
' Case LCase(Right(e.FullPath, 3) = "exe"
' Exit Selec
' Case LCase(Right(e.FullPath, 3) = "vbs"
' Exit Selec
' Case Els
' Exit Su
'End Selec

Dim changeTyp
Dim shostname As Strin
If e.ChangeType = WatcherChangeTypes.Created The
changeType = "created
End I

shostname = System.Net.Dns.GetHostNam

'Console.WriteLine(shostname & ": file '" & e.FullPath & "' was " & changeType
Dim MyLog As New EventLog ' create a new event log

If Not MyLog.SourceExists("FSWatcher2") The
MyLog.CreateEventSource("FSWatcher2", "FSWatcher2 Log") ' Create Log
End I
MyLog.Source = "FSWatcher2 Log
' Write to the Log
MyLog.WriteEntry("FSWatcher2 Log", "FSWatcher2 alert: " &
CStr(TimeOfDay) & vbCrLf & shostname & " - file '" &
e.FullPath & "' was " & changeType

End Su
Protected Overrides Sub OnStop(
' Add code here to perform any tear-down necessary to stop your service
End Su

End Clas

Jul 21 '05 #1
0 1290

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rich Miller | last post by:
Previously posted on the VB newsgroup with no replies, so any ideas appreciated. I have written a service application in VB (VS.Net 2003). On start, the service creates an object that...
1
by: Joshua Mann | last post by:
I have created a windows service which runs the FileSystemWatcher component. If the service is running and monitoring a directory (ex. "c:\temp") during heavy folder access the service generates...
1
by: A Hirsi | last post by:
Hi I am planning to use the filesystemwatcher to monitor an ftp site for changes to a file. I would like to download the file if it changes and process it locally. I read somewhere that I do not...
3
by: Craig Thompson | last post by:
I've attempted to write a windows service that creates one FileSystemWatcher for each entry in a XML config file. Everything start perfrectly and runs as I expect for about 5 minutes and then...
2
by: Jet Leung | last post by:
Hi all, I had made a program to watching files in my directory. I had used a instance of FileSystemWatcher to do my work.And I had add some events of the FileSystemWatcher , for example onChange,...
2
by: Sacha Korell | last post by:
I need to set up a FileSystemWatcher in my web application (to automatically process uploaded files) and I'm trying to decide where to set it up. I would like to keep it within the web app, but it...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
0
by: Rich Miller | last post by:
Any ideas appreciated. I have written a service application in VB (VS.Net 2003). On start, the service creates an object that instantiates a System.IO.FileSystemWatcher like so (the _watcher is...
5
by: =?Utf-8?B?Sm9obiBT?= | last post by:
I am trying to find out if there is a way to tell if there is already a filesystemwatcher (created by a webservice) monitoring a folder. I have a webservice that creates a filesystemwatcher,...
1
by: D2 | last post by:
Hi, We are using FileSystemWatcher class in a windows service to monitor a directory "d:\abc". This path is configured in a config file. When the service is running and FSW is watching this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.