Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok. I was looking for a code that can retrive me all open windows, but all I have found was using winAPI functions and this code

MIDL
foreach (Process p in Process.GetProcesses(System.Environment.MachineName))
            {
                if (p.MainWindowHandle != IntPtr.Zero)
                    p.Kill();

            }

Well, it works but it don't show me the explorer's windows, there's any way for showing the explorer's windows using code like a similar code like that one without using the WinAPI?
Posted

Use GetProcessesByName
foreach (Process p in Process.GetProcessesByName("explorer")) 
{
	//p.Kill();
}


Why you want to kill explorer?!!
 
Share this answer
 
v3
Comments
[no name] 20-Apr-11 7:02am    
it's not i want to kill explorer, i just want to kill some windows. And it's for a school project!
CodingLover 20-Apr-11 7:29am    
so you should know what are they in advance.
Prerak Patel 20-Apr-11 7:36am    
Then just don't kill it, do whatever. You get explorer processes with this code.
[no name] 20-Apr-11 10:19am    
thanks for the answer, I've got a way with that!!!
Prerak Patel 20-Apr-11 23:37pm    
Good, then you can mark it as solved now. You are welcome.
Dealing with the current user is more secure as well as more easy to control. Codeproject has a nice article on that.

How To Get Process Owner ID and Current User SID[^]
 
Share this answer
 
Comments
[no name] 20-Apr-11 10:23am    
Well, your solutions feels like a little harder, that's because a don't know anything of win32 api but thanks for the solution...
CodingLover 22-Apr-11 0:15am    
win32 api is bit mess to understand. but the most suitable in most of the time.
Sergey Alexandrovich Kryukov 20-Apr-11 18:19pm    
Did you try to remove it? Very dangerous, bad idea!
See my "Solution".
--SA
Did you ever try to remove Explorer process? It would remove system tray, "Start" meny…
Unsafe vandalizing practice! Don't do it!

—SA
 
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