By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,967 Members | 1,167 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,967 IT Pros & Developers. It's quick & easy.

Terminating of Process which was started mit cmd /c

P: n/a
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();

}


Nov 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You can use the Process.GetProcessByName method, which returns an instance of
the Process class. Then use the Kill method.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"SMichal" wrote:
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();

}


Nov 21 '06 #2

P: n/a
"SMichal" <mi************@trygon-softwareberatung.dewrote in message
news:O9**************@TK2MSFTNGP06.phx.gbl...
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..

Nov 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.