How kill a process with the exe filename?

sitajony

Active Member
Licensed User
Hello, I need to kill a process before update it in C#, I can't use dzHW.dll coz I want get a one EXE file without dll file...
I searched for GetWindowThreadProcessId(IntPtr hwnd) and GetProcessById(Int32 id) but how get the process id? (PID) from an exe filename?
And how check if it's running? I tried with FindWindow but I need also the Windows Handle and I don't know the Window handle...

Anyone can help me?
Thanks for your replies!
 

agraham

Expert
Licensed User
Longtime User
Assuming you are on the desktop you can get an array of Process objects representing running processes with Process.GetProcesses or Process.GetProcessesByName for a specific exe. Once you have a Process object for the exe you can have your wicked way with it.
 

sitajony

Active Member
Licensed User
Yes I know how do it on Desktop but GetProcessByName doesn't exist on compact Framework... Is there an other way?

And with ToolHelp32? In dzHW library in VB I see some stuff with ToolHelp32 in VB but unable to understand how use it...
 
Last edited:

sitajony

Active Member
Licensed User
Thanks! Finaly a great response, each time I found only few informations but not enough... Thanks again :) I hope it'll works :)
 
Top