473,499 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get processes ID and Kill

Hi All,

I need to get all the IDs of specific process and kill all the
instances of that process.

Something like:

// theArray get all the Excel proc IDs in the Task manager
string[] theArray = new string[100];

//there can be more then one instance of excel in Task manager
theArray = GetAllProcessID("Excel");
for (int i = 1; i 100; i++)
killProcessbyID(theArray[i]);

Thanks for the help.

Dec 24 '06 #1
2 20592

al********@gmail.com wrote:
Hi All,

I need to get all the IDs of specific process and kill all the
instances of that process.

Something like:

// theArray get all the Excel proc IDs in the Task manager
string[] theArray = new string[100];

//there can be more then one instance of excel in Task manager
theArray = GetAllProcessID("Excel");
for (int i = 1; i 100; i++)
killProcessbyID(theArray[i]);

Thanks for the help.
NM,
Just found the solution. atleast I learned something. Always google
before you post a new post :(.

Comments are wellcome.

private void button1_Click(object sender, System.EventArgs e)
{
string a = "";
Process[] procList = Process.GetProcesses();
for ( int i=0; i<procList.Length; i++)
{
if(procList[i].ProcessName.ToString() == "EXCEL")
{
a+= "Process ID="+procList[i].Id +"\t"+"Process
Name="+procList[i].ProcessName+"\n";
procList[i].Kill();
}
}
MessageBox.Show(a);
}

Dec 24 '06 #2
Hi

Replacing for loop with for each would look good. Does not effect any
functionality.

string a = "";
Process[] procList = Process.GetProcesses();

foreach (Process p in procList)
{
if (p.ProcessName.ToString() == "EXCEL")
{
a += "Process ID=" + p.Id + "\t" + "Process Name=" +
p.ProcessName + "\n";
p.Kill();
}
}

MessageBox.Show(a);

should work fine and looks readable.

Thanks
-Srinivas.

al********@gmail.com wrote:
Hi All,

I need to get all the IDs of specific process and kill all the
instances of that process.

Something like:

// theArray get all the Excel proc IDs in the Task manager
string[] theArray = new string[100];

//there can be more then one instance of excel in Task manager
theArray = GetAllProcessID("Excel");
for (int i = 1; i 100; i++)
killProcessbyID(theArray[i]);

Thanks for the help.
Dec 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7029
by: Bob Swerdlow | last post by:
My application starts up a number of processes for various purposes using: self.popen = popen2.Popen3("/usr/local/bin/python -O "myscript.py") and then shuts them down when appropriate with...
5
5210
by: Thomas Chan | last post by:
I have an application that need to launch acrobat reader. But before I open acrobat reader, I want to check there is any existing acrobat reader opening and kill them first. What can I do? Can...
6
10556
by: ujjc001 | last post by:
Hello all. I have many connections that are sleeping. I can right click, kill, up to 2 at a time. It takes about 20 seconds to kill it. Is that normal? I tried to make a stored procedure to...
3
6375
by: pattanawadee | last post by:
Deall All, Could anybody suggestion me How to kill all inherrit processes (sibling child,previous and parent process) in the case I know only child process id and user id, For example I strart...
7
2966
by: Joe | last post by:
If I'm using process.kill, I can only kill processes, which are created in the same login session. (I'm using win2000, I'm in the local admin group) Processes created by me in earlier logins or...
2
11185
by: schreckmail | last post by:
Hi all! I'm launching a subprocess using the following code, and I'd like to kill off all associated subprocesses after a given timeout: myproc = popen2.Popen3(command) Now, because the...
8
16118
by: mandydhaliwal | last post by:
Hi all, I am porting a win32 c++ program on Linux which first reads a list of processes and their paths from a file.Then this program should launch all of thesese processes. I tried to...
1
1294
by: Dave | last post by:
I'm using a small vb.net app to open up applications within a Citrix/terminal services session. Under some conditions, I'd like the app to close those applications. However, code I've found online...
4
3282
by: Bill Nguyen | last post by:
I ran into this problem in a Terminal Server environment When trying to kill all processes having the same name (to avoid hanging instances of this process), my users ran into permission problem...
4
2640
by: geoffbache | last post by:
Hi all, I've always wondered why os.kill isn't supported on Windows. I found a discussion somewhere from 2006 about this so it seems others have wanted it, but still nothing. So I have a...
0
7130
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,...
0
7007
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...
1
6893
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...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4918
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
3098
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...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
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 ...
1
664
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.