Hi,
I have added a FileSystemWatcher to my Service program and build and installed it successfully. But when i start the service it says,
Error. "Not of a valid form"
Can this object be used only on a valid form Or am I making any stupid mistake
This is the code I have written.
Public Class FlashTrapperService
Dim WithEvents fswF****ch As System.IO.FileSystemWatcher
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
fswF****ch = New System.IO.FileSystemWatcher()
username = My.User.Name
username = username.Remove(0, username.LastIndexOf( "\") + 1)
If My.Computer.FileSystem.DirectoryExists("C:\Documents and Settings\" & username & "\Local Settings\Temporary Internet Files") Then
folderpath = "C:\Documents and Settings\" & username & "\Local Settings\Temporary Internet Files"
ElseIf My.Computer.FileSystem.DirectoryExists("D:\Documents and Settings\" & username & "\Local Settings\Temporary Internet Files") Then
folderpath = "D:\Documents and Settings\" & username & "\Local Settings\Temporary Internet Files"
End If
fswF****ch.Path = folderpath
fswF****ch.NotifyFilter = (IO.NotifyFilters.LastAccess Or IO.NotifyFilters.LastWrite Or IO.NotifyFilters.FileName Or IO.NotifyFilters.DirectoryName)
fswF****ch.Filter = "*.swf"
AddHandler fswF****ch.Changed, AddressOf fswF****ch_Changed
AddHandler fswF****ch.Created, AddressOf fswF****ch_Changed
fswF****ch.EnableRaisingEvents = True
fswF****ch.IncludeSubdirectories = True
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
fswF****ch.EnableRaisingEvents = False
End Sub
Private Sub fswF****ch_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
flashfolder = "D:\TrappedFlashFiles\"
filename = e.FullPath
filename = filename.Remove(0, filename.LastIndexOf( "\") + 1)
filename = flashfolder & filename
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
My.Computer.FileSystem.CopyFile(e.FullPath, filename, True)
End If
End Sub
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
End Class
Thanks for your help.
Regards
Visual Basic12
|