如何将(字节)数据流转换为vb.net中的字符串



我的程序必须使用套接字编程从服务器读取数据,以杀死远程PC中的进程。从套接字连接转换NetStream后,我将流转换为字符串,但是由于输入字符串未转换为字符串,因此无法杀死流程。我很困惑,因为我能够使用字符串方法,例如.remove((,但是当我将输入变量传递给函数killprocess时,该过程不会删除。

'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
Dim p() As Process
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    p = Process.GetProcessesByName("taskmgr")
    If p.Count > 0 Then
        Dim pList() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("notepad")
        For Each proc As System.Diagnostics.Process In pList
            proc.Kill()
        Next
    End If
End Sub

相关内容

  • 没有找到相关文章

最新更新