I have written two Windows Services that call asp pages. Now I am needing a filesystemwatcher service to call a vbscript whenever something
changes in a specific folder. The vbscript runs perfectly but I haven't been able to get the Windows Service to run the vbscript. The code for
my service is below. Any suggestions would be greatly appreciated.
Imports System.IO
Public Class ConvertExcel
Dim fsw As 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.
fsw = New FileSystemWatcher()
fsw.Path = "C:\Windows\Excel"
fsw.Filter = "*.xls"
fsw.IncludeSubdirectories = False
fsw.EnableRaisingEvents = True
AddHandler fsw.Created, New FileSystemEventHandler(AddressOf file_created)
End Sub
Public Sub file_created(ByVal obj As Object, ByVal e As FileSystemEventArgs)
Dim foo As New System.Diagnostics.Process
foo.StartInfo.WorkingDirectory = "C:\BatchFiles\"
foo.StartInfo.RedirectStandardOutput = True
foo.StartInfo.FileName = "cmd.exe"
foo.StartInfo.Arguments = "%comspec% /C cscript.exe //Nologo C:\BatchFiles\Upload_Converted_Excel_File.vbs"
foo.StartInfo.UseShellExecute = False
foo.StartInfo.CreateNoWindow = True
foo.Start()
foo.WaitForExit()
foo.Dispose()
End Sub
Protected Overrides Sub OnStop()
' Add code here to
perform any tear-down necessary to stop your service.
End Sub
End Class