Terminating of Process which was started mit cmd /c

S

SMichal

Hi. how can I terminate process which was started with cmd /c ? The Kill()
method terminates only that CMD.exe

string cdHome = @"C:\Temp\";
string localhost = "chsaXY";
string userName = "aaa";
string password = "bbb";
string processFile = @"C:\Data.prc";
string temp = @"C:\Temp\";
string args = @" /c " + cdHome + "Notepad.exe " + " -n" + localhost + " -u"
+

userName + " -p" + password + " <" + prozessFile + " >>" + temp +
"testlog.txt";

Process proc = new Process();

proc.StartInfo.FileName = "cmd.exe";

proc.StartInfo.Arguments = args;

int time = 60000

proc.WaitForExit(time); // wait only with our timeout

if (!proc.HasExited)

{

proc.Kill(); // time is over - kill that process

proc.WaitForExit();

}
 
G

Guest

You can use the Process.GetProcessByName method, which returns an instance of
the Process class. Then use the Kill method.
Peter
 
J

John Vottero

SMichal said:
Hi. how can I terminate process which was started with cmd /c ? The Kill()
method terminates only that CMD.exe

You can't. You have to call CreateJobObject to create a Job and add the
initial CMD.EXE process to that job then, any processes created by the
CMD.EXE process will become part of the job (unless they request otherwise).
Then, when you want to kill, you call TerminateJobObject and all the
processes that are part of the job are killed..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top