My program has to read a data from a server using socket programming to kill processes in a remote pc. After i convert the netstream from the socket connection, I convert the stream into String but I'm unable to kill the processes because the input string is not converted to string. I'm puzzled since I'm able to use string methods such as .remove(), but when i pass the input variable to the function killProcess the processess is not deleted.
'socket datastream
If NetStream.DataAvailable Then
Dim bytes(TCPClient.ReceiveBufferSize) As Byte
Dim input As String
NetStream.Read(bytes, 0, CInt(TcpClient.ReceiveBufferSize))
lblConnectStatus.Text = ("Server was disconnected ")
input = Encoding.ASCII.GetString(bytes)
If input.StartsWith("kill") Then
input = input.Remove(0, 4)
Try
KillProcess(input)
Catch ex As Exception
End Try
End if
End if
'kill process function
'this function works when i write the program name manually eg.:"notepad"
'but it doesn't work when i pass the parameter pid for the killProcess() function
Private Sub KillProcess(ByVal pid As String)
For Each P As Process In System.Diagnostics.Process.GetProcessesByName(pid)
P.Kill()
Next
End Sub