I developed a Webpage in ASP.NET – the page has a button that starts a DOS-Program on click.
Here is the Code:
if (!String.IsNullOrEmpty(endTime))
{
Process p = new Process();
p.StartInfo.WorkingDirectory = Server.MapPath("~/");
p.StartInfo.FileName = Server.MapPath(apiFile);
try
{
p.Start();
}
catch
{
throw new Exception(
"Requested process (" + p.StartInfo.FileName + ") could not be started. Page: Api.aspx.cs, Method: UploadBtn_Click()");
}
System.Threading.Thread.Sleep(5000);
Response.Redirect(Request.Url.ToString());
}
The code works fine and starts the Process.
Now the Problem:
I click on the button and the process starts (I see this in the database) and the program works fine, however, I want to stop the process now, but don’t know how.
There isn’t a DOS-Window where I can click “CTRL + C” or something.
What can I do to stop the process?
And which User is used for starting the Process?
Just use
Process.Kill:UPDATE:
Because of your comment, I provide this as an alternative:
To kill a process without code, use the task manager (open it by using CTRL + SHIFT + ESC or CTRL + ALT + DEL -> Task manager), navigate to the “Processes” tab, choose “Show processes from all users”, select your process and click “End process”…