76 793
Assignments Done
Successfully Done
In June 2019

Answer to Question #21197 in C# for saurabh mishra

Question #21197
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.
Expert's answer
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

public MainForm() : base()
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);


class Program
public static void Main()
Application.Run(new MainForm());

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions