473,412 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Terminating of Process which was started mit cmd /c

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
2 2339
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Earl Eiland | last post by:
I'm running a PyWin program that executes another program using subprocess.Popen(). Unfortunately, this other program isn't well behaved, and frequently terminates without terminating its process....
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
23
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an...
6
by: Tomaz Koritnik | last post by:
I have a class that runs one of it's method in another thread. I use Thread object to do this and inside ThreadMethod I have an infinite loop: While (true) { // do something Thread.Sleep(100);...
5
by: GTS | last post by:
Hi All, I am spawning a process from a service. The spawned process hungs for various reasons, (corrupted data, deadlock). I am expecting the process has to complete the task with in the...
3
by: Nikolay Petrov | last post by:
I have a class which starts a process and redirects it's output and input. My class have a method which starts the process and another which stops it. How can I check if the process have been...
11
by: Jon Davis | last post by:
Does anyone know why using System.Diagnostics.Process to "wrap" a console application does not always transmit the I/O, depending on what processes you're trying to "consume"? PowerShell, for...
13
by: chuckie_9497 | last post by:
hello all you gurus. I am struggling with releasing com objects. I have isolated the problem to the code below. Objects are released and the process ends until I use "int k = sheet.Count;" Then...
9
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.