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