// Event handler
protected void btnCommand_Click(object sender, EventArgs e)
{
System.Diagnostics.ProcessStartInfo objProcessStartInfo =
new System.Diagnostics.ProcessStartInfo("CMD.exe", "/C " + "dir");
// CMD.exe is the name of the file which will execute.
// /C is the path name.
// dir is the command which will execute in command prompt.
objProcessStartInfo.CreateNoWindow = true; // This line will not create any new window for command prompt.
objProcessStartInfo.UseShellExecute = false;
// Set UseShellExecute to specify whether to start the process by using the operating system shell.
System.Diagnostics.Process objProcess =
System.Diagnostics.Process.Start(objProcessStartInfo);
objProcess.Close();
}