Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

C#
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");
            }
        }
Posted
Updated 12-Oct-15 17:16pm
v2
Comments
F-ES Sitecore 12-Oct-15 6:27am    
It'll probably be permission related. The account your code is running under won't have permission to do a lot of these tasks, you'll need to change the account of your anonymous user to a domain account with the required access.

Needless to say this is very bad design anyway.
CgKumar 12-Oct-15 6:40am    
Thanks for your comment. Did you have any suggestion how to handle the problem?
Philippe Mori 13-Oct-15 12:38pm    
Fix your design so you don't have to kill the process.

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.
 
Share this answer
 
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.
 
Share this answer
 
Comments
CgKumar 13-Oct-15 0:55am    
Actually the .exe file is copy from the server, save at client c drive and process to start from client c drive the .exe file. How could you said "NOT stop a process on the client machine and it can NOT launch an executable on a client machine". Please give me any suggestion if my code is wrong. Thanks.
Dave Kreskowiak 13-Oct-15 9:53am    
OK, so AGAIN, in what kind of application is this code running? Is it an ASP.NET app? A Windows Forms app? What? YES, IT MATTER GREATLY.
CgKumar 13-Oct-15 20:52pm    
It is for web application, using C# program. The program ASP.net i only used for design the web application.
Dave Kreskowiak 13-Oct-15 21:23pm    
OK, that wasn't exactly clear so, again, I'm going to assume this is solely an ASP.NET app written in C#. From the server, you can NOT stop a process on a client machine and can NOT launch a new process on it either.
CgKumar 13-Oct-15 21:37pm    
Did You have any suggestion to stop a process on a client machine? I'm only using my computer local host for test the program. Can you please help me...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900