I want to write a C# program which will launch an .exe (this is an easy job, I know how to do it.) but now I want to add some more functionality to it. I want to take user inputs to my program and want to pass them to running .exe as a input.Also I want to click on a particular button available on the exe window. Important thing is, I want to do it programatically without user knowledge that we are actually running that exe in background.
1
Expert's answer
2012-12-26T07:53:50-0500
using System; using System.Drawing; using System.Diagnostics; using System.Windows.Forms;
class MainForm : Form { Button execute; TextBox targetProcess;
public void ExecuteClick(object sender, EventArgs e) { string processToKill = targetProcess.Text; if (!processToKill.EndsWith(".exe")) processToKill += ".exe";
ProcessStartInfo startInfo = new ProcessStartInfo("taskkill", "/F /IM " + processToKill); startInfo.WindowStyle = ProcessWindowStyle.Hidden; //hide process window Process.Start(startInfo); }
public MainForm() : base() { this.SuspendLayout(); this.Size = new Size(150, 106); this.MaximizeBox = false; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.StartPosition = FormStartPosition.CenterScreen;
execute = new Button(); execute.Location = new Point(12, 36); execute.Size = new Size(120, 32);
execute.Text = "Kill process"; execute.Click += new EventHandler(ExecuteClick);
targetProcess = new TextBox(); targetProcess.Location = new Point(12, 12); targetProcess.Size = new Size(120, 32);
Comments
Leave a comment