What I want to make is a kill tracker for Wolfenstein enemy territory and I want the program to find kills and deaths in the game by reading from the console. W:ET is a quake 3 based game and I am not positive that this is the correct method for this but it would still be good to know in the future.
I want the program to find the game when and if it is running
Expand|Select|Wrap|Line Numbers
- Private Sub getProcesses(ByVal source As Object, ByVal e As System.Timers.ElapsedEventArgs)
- Dim dv As Integer = 0
- Try
- Dim ArrayProcess As Process() = Process.GetProcesses(MachineName)
- Dim TempProcess As Process
- For Each TempProcess In ArrayProcess
- Dim fmstr As String = "{0,-20}{1,5}"
- If TempProcess.ProcessName = "ET" Then
- lbl_gamestate.Text = "W:ET is running!"
- refreshT.Enabled = False
- gameRunning(TempProcess)
- Exit For
- Else
- lbl_gamestate.Text = "W:ET is not running!"
- End If
- Next TempProcess
- Catch ex As Exception
- Throw New Exception(ex.Message)
- End Try
- End Sub
Expand|Select|Wrap|Line Numbers
- Private Sub gameRunning(ByVal gameprocess As Process)
- Dim sr As IO.StreamReader = gameprocess.StandardOutput
- Dim sb As New System.Text.StringBuilder
- Dim input As Integer = sr.Read
- Do Until input = -1
- sb.Append(ChrW(input))
- input = sr.Read
- ListBox1.Items.Add(sr.ReadLine)
- MsgBox("durt")
- Loop
- If gameprocess.HasExited Then
- MsgBox("Game has closed!")
- End If
- End Sub
I thought it might have had something to do with RedirectStandar dError and/or RedirectStandar dOutput so I tried this
Expand|Select|Wrap|Line Numbers
- Private Sub gameRunning(ByVal gameprocess As Process)
- gameprocess.Kill()
- Dim et As New Process
- Dim filename As String = "c:\program files\wolfenstein - enemy territory" & "\" & "et.exe"
- Try
- If Exists(filename) Then
- et.StartInfo.Arguments = ""
- et.StartInfo.WorkingDirectory = "c:\program files\wolfenstein - enemy territory"
- et.StartInfo.FileName = "et.exe"
- et.StartInfo.RedirectStandardError = True
- et.StartInfo.RedirectStandardOutput = True
- et.Start()
- Else
- MsgBox("Blue Monkey Patch Selector was not installed correctly." & Chr(13) & "Please reinstall the program.")
- End If
- Catch ex As Exception
- End Try
- Dim sr As System.IO.StreamReader = et.StandardOutput
- Dim sre As System.IO.StreamReader = et.StandardError
- richtextbox1.Text = sr.ReadToEnd
- richtextbox1.Text = sre.ReadToEnd
- et.WaitForExit()
- startRefresh()
- End Sub
THX :-D