Help!
Trying to get the code working below but to no joy.
In short, I want to load an application ONCE and ONCE only during a given time period (in the example, it's notepad).
But I've got two problems (big ones too!!)
Firstly, Notepad doesn't open up. It loads as a process, you can check by looking at the windows task manager, but not as an app.
Secondly, I just can't seem to get the thing checking to see if the process is already running, and if it is, then ignore the init for the notepad.
Anyone any ideas?
Trying to get the code working below but to no joy.
In short, I want to load an application ONCE and ONCE only during a given time period (in the example, it's notepad).
But I've got two problems (big ones too!!)
Firstly, Notepad doesn't open up. It loads as a process, you can check by looking at the windows task manager, but not as an app.
Secondly, I just can't seem to get the thing checking to see if the process is already running, and if it is, then ignore the init for the notepad.
Anyone any ideas?
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.
_BatchImportProcess.StartInfo.FileName = "C:\WINDOWS\NotePad.Exe"
_BatchImportProcess.StartInfo.CreateNoWindow = False
_BatchImportProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
_BatchImportProcess.StartInfo.ErrorDialog = True
_BatchImportProcess.StartInfo.UseShellExecute = True
Timer1.Enabled = True
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
If Not _BatchImportProcess.HasExited = True Then
_BatchImportProcess.Kill()
End If
Timer1.Enabled = False
End Sub
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Timer1.Enabled = False
Dim _StartTime As New TimeSpan(10, 0, 0)
Dim _EndTime As New TimeSpan(18, 1, 0)
Dim _Start As Integer = Now.TimeOfDay.CompareTo(_StartTime)
Dim _End As Integer = Now.TimeOfDay.CompareTo(_EndTime)
Dim c As Process()
c = Process.GetProcessesByName(_BatchImportProcess.ProcessName.ToString)
If _Start = 1 And _End = -1 And c.Length = 0 Then
EventLog1.WriteEntry("Watson Batch Import", "Batch entry started at " & Now.ToLongTimeString & " on " & Now.ToLongDateString)
_BatchImportProcess.Start()
End If
Timer1.Enabled = True
End Sub