如何杀死任务或停止在ASP.net C#中运行.exe文件? [英] How to Kill Task or stop running .exe file in ASP.net C#?

查看:124
本文介绍了如何杀死任务或停止在ASP.net C#中运行.exe文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了一个问题,那就是杀死正在运行的任务.我的项目流程是这样的:1)杀死正在运行的test.exe程序; 2)从服务器复制test.exe文件; 3)粘贴到C盘中; 4)从C驱动器运行test.exe文件.

因此,每次我单击按钮时,test.exe都应关闭并重新打开.这是因为要从服务器获取更新的test.exe文件.但是问题是test.exe无法关闭或杀死.请帮帮我....

代码:

Here i have a problem which is to kill a running task. My project flow is like this: 1) kill running test.exe program; 2) Copy test.exe file from server; 3) paste into the C drive; 4) run the test.exe file from C drive.

Thus each time i click the button, the test.exe should close and open back. It is because to get the updated test.exe file from server. But the problem is the test.exe is cannot close or kill. Please help me....

Code:

protected void Button1_Click(object sender, EventArgs e)
        {
            {
                //Kill the running program file
                foreach (var proc in Process.GetProcessesByName("test"))
                {
                    proc.Kill();
                }
            }
            try
            {
                //To Choose the path at server and c drive
                string fileName = "test.exe";
                string sourcepath = @"\\192.168.5.10\fbar\TOOLS\";
                string targetpath = @"c:\Test1\";

                string sourcefile = System.IO.Path.Combine(sourcepath, fileName);
                string destfile = System.IO.Path.Combine(targetpath, fileName);

                //Create Test1 folder if it not created
                if (!System.IO.Directory.Exists(targetpath))
                {
                    System.IO.Directory.CreateDirectory(targetpath);
                }
                //Copy the .exe file from server to c drive
                {
                    System.IO.File.Copy(sourcefile, destfile, true);
                }
                //Start the .exe file from c drive
                {
                    System.Diagnostics.Process.Start(@"c:\Test1\test.exe");
                }
            }
         catch (Exception)
            {
             //***Start this if file .exe cannot copy from server
                System.Diagnostics.Process.Start(@"c:\Test1\test.exe");
            }
        }

推荐答案

我准备解决问题​​.我的错误是放置.exe文件的完整路径名.实际上,我需要对它进行测试"才能杀死它.
I m settle ready the problem. my mistake is put the full path name of the .exe file. Actually i need to put "test" for kill it.


我在这里做一个假设.您不会说您发布的代码在哪种应用程序中.我将假设它是ASP.NET代码.

话虽如此,您了解ASP.NET代码完全在服务器端运行,对吗?它没有一个在客户端上运行.

您的ASP.NET代码无法在客户端计算机上停止进程,也无法在客户端计算机上启动可执行文件.
I''m making an assumption here. You don''t say what kind of application this code you posted is in. I''m going to assume it''s ASP.NET code.

Having said that, you understand that ASP.NET code runs ENTIRELY server-side, right? NONE of it runs on the client.

Your ASP.NET code can NOT stop a process on the client machine and it can NOT launch an executable on a client machine.


这篇关于如何杀死任务或停止在ASP.net C#中运行.exe文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆