473,795 Members | 3,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.pr c";
string temp = @"C:\Temp\";
string args = @" /c " + cdHome + "Notepad.ex e " + " -n" + localhost + " -u"
+

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

Process proc = new Process();

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

proc.StartInfo. Arguments = args;

int time = 60000

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

if (!proc.HasExite d)

{

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

proc.WaitForExi t();

}


Nov 21 '06 #1
2 2372
You can use the Process.GetProc essByName 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.pr c";
string temp = @"C:\Temp\";
string args = @" /c " + cdHome + "Notepad.ex e " + " -n" + localhost + " -u"
+

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

Process proc = new Process();

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

proc.StartInfo. Arguments = args;

int time = 60000

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

if (!proc.HasExite d)

{

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

proc.WaitForExi t();

}


Nov 21 '06 #2
"SMichal" <mi************ @trygon-softwareberatun g.dewrote in message
news:O9******** ******@TK2MSFTN GP06.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 TerminateJobObj ect 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
2082
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. After this happens enough times, all my memory is tied up, and the machine crashes. Using subprocess.poll(), I can keep my program from hanging, by timing out the process, and starting anew. This still leaves the previous process hogging...
9
7273
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 stopping. Please advise how to stop the service. Thanks, SP
23
7596
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 unrecoverable error occurs. When that case occurs, I create a ServiceController object and call the Stop() method. However - I get an exception thrown saying access denied. If I switch to using the LocalService account it works fine, but I lose...
6
23745
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); } The problem is that I don't know how to terminate the thread when my class
5
3090
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 expected time limit, if it exceeds the limit I want to terminate the process (no mercy or graceful, just terminate the process). The spawnng of the process, counting the time and termination of process all done in C++. Some time I am not able to...
3
1278
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 already started, so I don't try to start it again, and how to check if the process is not running so i don't try to stop again? code: Public Class ProcEx Private p As Process Public Sub StartProcess()
11
11964
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 example, does not seem to process any I/O through the Process object. I know that in the case of PowerShell there are better ways to "wrap" the console by directly interfacing with the assemblies of System.Management.Automation or some similarly...
13
3014
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 the process does not end. So I feel confident the problem occurrs here. It appears another reference is created that needs to be closed. Can anyone tell me how to do this? :) Thank you Excel.Workbook workbook =
9
6496
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 hangs at this point. How should I handle these kind of commands (ping 127.0.0.1) with
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6780
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.