I'm having trouble with this. Basically what I'm trying to accomplish is a server restarter. It needs to look for the server to close. I was thinking just look for the process to close. But I'm not sure how to do it. Could someone help please
If you write the server code you could also add a named Mutex (see MSDN Mutex class), which your server creates. When the server crashes the mutex will also die. Check the existence of that mutex in your watcher. If you come up with a really unique mutex name, that collides not as easily as process names might do.
Thanks for this info. I'm still kind of confused as I am just learning VB, but your help is very much appreciated. If theres more specific info you could give I would be much obliged. If not thats quite alright you've helped quite a bit already. I will mark this post as answered but if you want I wouldn't mind more information if possible.
Do you use the term "server" for your hardware or your software If software: is your server implementes as Windows Service If yes: in the Services console open the properties of your service and configure "Recovery" to restart your service after if failed. Basically Windows gives you this process watchdog feature for free.
For anyone who may be looking for a solution to this here is the code I used. It may not be the best way to do it. But it works
Public
Class Form1
Public proc1 As String
Dim proc As New System.Diagnostics.Process()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
timer.Interval =
Integer.Parse(intBox.Text)
timer.Enabled =
True
start()
End Sub
Private Sub start()
proc1 = procBox.Text
' Fill-up StartInfo
proc.StartInfo.UseShellExecute =
True
proc.StartInfo.FileName = proc1
' Start the process
proc.Start()
End Sub
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick
If (proc.HasExited) Then
start()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OK, in your watching app use System.Diagnostics.Process.GetProcessesByName to check if your app is returned in that collection. Do that check on a regular basis e.g. with a Timer component.
Watching a process.
John Hennesey
If you write the server code you could also add a named Mutex (see MSDN Mutex class), which your server creates. When the server crashes the mutex will also die. Check the existence of that mutex in your watcher. If you come up with a really unique mutex name, that collides not as easily as process names might do.
--
SvenC
Corngood
uaurgent
GetProcessesByName returns an array of Process objects, because there can be more with the same name. Loop that array with
for each oProc As Process in Process.GetProcessesByName("yourApp")
' see oProc.MainModule.ModuleName or .FileName for your process name and or path
next
You could use the path if you now where your app is installed to see if it is really your app.
--
SvenC
Michael Herman - Parallelspace
Do you use the term "server" for your hardware or your software If software: is your server implementes as Windows Service If yes: in the Services console open the properties of your service and configure "Recovery" to restart your service after if failed. Basically Windows gives you this process watchdog feature for free.
--
SvenC
Mateusz Rajca
Alexandre Defalque
For anyone who may be looking for a solution to this here is the code I used. It may not be the best way to do it. But it works
Public
Class Form1 Public proc1 As String Dim proc As New System.Diagnostics.Process() Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clicktimer.Interval =
Integer.Parse(intBox.Text)timer.Enabled =
Truestart()
End Sub Private Sub start()proc1 = procBox.Text
' Fill-up StartInfoproc.StartInfo.UseShellExecute =
Trueproc.StartInfo.FileName = proc1
' Start the processproc.Start()
End Sub Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick If (proc.HasExited) Thenstart()
End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Clicktimer.Enabled =
False End SubEnd
Classvenp
OK, in your watching app use System.Diagnostics.Process.GetProcessesByName to check if your app is returned in that collection. Do that check on a regular basis e.g. with a Timer component.
--
SvenC
Chrisull
Sorry I should have been more specific. Server is refering to software and no it's not registered as a service.
I could have it registered as one. But I would much rather understand how to do it this way.
rolian