I'm trying to Close a process within C# but how do I check if is open first? Users asked for this feature and some of them will be still using the close button of the other process.
So, right now works fine:
Process.GetProcessesByName("ProcessName")[0].CloseMainWindow();
Now, how do I check first that it exists, this doesn't work:
if ( Process.GetProcessesByName("ProcessName")[0] != null ) {...}
You could use GetProcessesByName
like so:
foreach(var application in Process.GetProcessesByName("ApplicationName"))
{
application.CloseMainWindow();
}
If you meant to kill the application, then you could do this instead:
foreach(var application in Process.GetProcessesByName("ApplicationName"))
{
application.Kill();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With