Get status from exe based on command line

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
So basically I want to get status of the process based on the command line that the process runs

Now I have 3 gaming servers that run with same process named srcds.exe
I know how to extract the command line from the exe to split and tell which process is for which game, since I know that the command line parameter for every process
This is the code I use
<pre class="prettyprint lang-vb Dim listdata As New List(Of String)
Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_Process WHERE Name=srcds.exe")
For Each process As ManagementObject In searcher.Get()
listdata.Add(process("CommandLine").ToString)
Next[/code]
And my "search to see if process is correct" code is
<pre class="prettyprint Dim game1 As String = "srcds.exe -game csgo -console +map de_dust -usercon +port 27016 +game_type 0 +game_mode 1 +mapgroup mg_bomb"

Try
If String.Compare(listdata.Item(0), game1) Then
csgo.Text = "Running"
csgo.ForeColor = Color.LimeGreen
Else
csgo.Text = "Stopped"
csgo.ForeColor = Color.Red
End If
Catch ex As Exception
csgo.Text = "Stopped"
csgo.ForeColor = Color.Red
End Try[/code]
<br/>
Now this is working fine but Ive noticed an issue with the
<pre class="prettyprint listdata.Item(0)[/code]
If this process runs second and say another instance of srcds.exe is running with another command line argument, my correct item will not be 0 but rather 1 or 2 (as I said I run 3 processes)
How can I always make sure I get details from correct process?
Not sure if you understand what I try to do but hope you do


View the full article
 
Back
Top