473,326 Members | 2,168 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,326 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 1289

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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.