Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Dear All,

I am making a windows desktop application. The problem I am facing is that I had opened windows explorer programatically using following command:
System.Diagnostics.Process.Start("Explorer.exe",@"c:\" + LearnerID );

I will search for specific file in that particular location.
and I want to close the explorer programatically.

I am using:
KillProcessByUserName("explorer.exe", Environment.UserName);

function to close that particular explorer.
but the problem is that the search explorer will not get closed. I would like to know how to close that search window explorer.

Any kind of link, suggestion and specially expert advice would be highly appreciated.

Thanks & Regards
Balkrishna Raut
Posted
Updated 21-Dec-10 18:45pm
v3

See the basic idea while doing this kind of work is to get the handle of the application first which you are going to open. When you have to close the application you will use the same handle (that you stored before while opening) to close it.

Code help:

C#
string processName = "Process1";

foreach (Process proc in Process.GetProcessesByName(processName))
      proc.Kill();


Links for reference:

http://dotnetperls.com/kill[^]

or

http://www.c-sharpcorner.com/UploadFile/scottlysle/ProcessKillCSharp04302008060422AM/ProcessKillCSharp.aspx[^]
 
Share this answer
 
Comments
JF2015 22-Dec-10 1:34am    
The problem is that this is not possible for the explorer, since it can't be closed easily without messing up with windows.
Wild-Programmer 22-Dec-10 1:36am    
Yes true, explorer is a single process.
Hi,

Keep Process object for further use.

Process TestPro=System.Diagnostics.Process.Start("Explorer.exe",@"c:\" + LearnerID );

With TestPro object you can get its process id by that can be use for killing process or just make a dictionary with process object and its id.

Process.GetProcessById();
 
Share this answer
 

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