Thank you Crazypennie for your friendly help and good suggestion.
Hi Alex,
Welcometo MSDN forums!
Here is code sample: How to create a Windows Service and check if specified application has been run via Timer object in VB.NET.
|
Public Class Service1
Private Timer1 As System.Timers.Timer
Protected Overrides Sub OnStart(ByVal args() As String)
Timer1 = New System.Timers.Timer()
AddHandler Timer1.Elapsed, AddressOf Timer_Elapsed
Timer1.Interval = 1000
Timer1.Start()
End Sub
Protected Overrides Sub OnStop()
Timer1.Stop()
End Sub
Private Sub Timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
'Check if your application has been run.
Dim proeslist As Process() = Process.GetProcessesByName("ApplicationName")
If proeslist.Count = 0 Then
Process.Start("D:\AppFolder\AppName.exe") ' Here start your application
End If
' Additionally, you can check each process'title and name like this:
Dim pro As Process
For Each pro In proeslist
Dim winTitle As String = pro.MainWindowTitle
Dim pName As String = pro.ProcessName
Next
End Sub
End Class
|
Best regards,
Martin Xie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.