Click here to Skip to main content
15,938,848 members
Please Sign up or sign in to vote.
2.29/5 (4 votes)
See more:
Hi All,

I need to develop the application for creating process and kill that particular process file from the whole processes.

Note:
1. I opened one excel sheet,
2. Now I creating another excel sheet through vb.net runtime programatically.
3. I want to kill the second process alone through programatically.
4. Do not kill first process

Thanks in Advance.
Posted
Updated 26-Apr-18 20:35pm
v3
Comments
[no name] 19-May-14 7:29am    
Okay so get a list of process running, find the process that you want, if found kill it.
Richard MacCutchan 19-May-14 7:29am    
You have not shown how you create the process, so it is difficult to suggest the best way of stopping it. As to question 5, it does not make much sense.
Mohankumar.Engain 19-May-14 7:33am    
I dont want to kill whole excel process, I need to kill only one of excel process. Remaining excel files are no need to close.
Nelek 19-May-14 7:53am    
Step 1) Do a little research. Google is a good start point
Step 2) Start coding
Step 3) Compile and use the debug to solve little issues
Step 4) When you get a problem you don't know how to solve but at least you tried it, then come back and ask for something concrete with a snippet of the code giving problems

Sorry if this is not the answer you were looking for. But your question is a bit too wide to be answered at the "Quick" Answers. It is better and you get faster help if you make 10 concrete questions about concrete problems, than a big question about a "how-to guide"

In addition, please read:
What have you tried?[^]
How to ask a question?[^]
ZurdoDev 19-May-14 8:19am    
Since you created the process in code you can easily kill it in code. Where are you stuck?

If you have something oExcel = Excel.Application then you can do oExcel.Quit();

Here you go...


VB
Dim p As Process
p = New Process()
p.StartInfo.FileName = "filename_with_complete_path.xls"

p.Start()


and to close it

p.Kill()


If the file is to be closed in some other function than the one in which it was opened, declare the process variable
'p'
globally (or within proper scope as per your requirement)
 
Share this answer
 
v2
If you are creating/opening an excel file through code, just close that file and dispose the object that you used to create/open the excel file.

If you post the code how you are creating/opening the file, then I may try to give you a specific solution.

For the time being lets assume you have created an object "excl" for excel application and another object "wrkSht" for the required work sheet.

then just use

wrkSht.Save()
wrkSht.Dispose()
excl.Dispose()

I dont think that any one would advice killing the excel process, when there are more managed ways to do what you want :)
 
Share this answer
 
v2
Comments
Mohankumar.Engain 21-May-14 1:56am    
Hi Kartikguha,
I have Following code:
----------------------
Process.Start("C:\File.xls")
Once this above process is started then I want to get this excel process id
but I wrote below code I am getting visual studio process id, How can I get This excel Id through code?
Dim s2 = Process.GetCurrentProcess().Id
Hi Mohankumar,

1/ we have to select the newely created process PID

C#
Process myProc = Process.Start("process full path");
int processId = myProc.Id;



2/ to kill the process based on its PID

C#
//we use the PID to select and kill that specific process

Process processes = Process.GetProcessById(processId);
processes.Kill();


Hope it helps.
 
Share this answer
 
Comments
kartikguha 23-May-14 6:01am    
I dont think @Mohankumar.Engain have any requirement for identifying the processId, all he wants to do is to kill the excel.exe process created programatically.

Process processes = Process.GetProcessById(processId);

Here in effect 'processes' refers to 'myProc' only.
So why not directly kill 'myProc' (which is what I had done in my solution)?

And by the way

Process.GetProcessById(processId);

does not returns a list of processes (as processId is unique for each process), but an instance of the process having specified processId. So the name 'processes' does not make sense to me...

But looking at your total reputation points, I think it is just a typo :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900