- Home /
Process.GetProcessesByName(string str); not working
Hi,
System.Diagnostics.Process.GetProcessesByName("notepad");
This line of code is not working in unity for me. This works well in a non-unity mono project
I get the following error when ruining this line of code in unity 4.2.1f4:
InvalidOperationException: Process has exited, so the requested information is not available. System.Diagnostics.Process.get_ProcessName () (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_ProcessName () System.Diagnostics.Process.GetProcessesByName (System.String processName)
I have no idea why its not working, any ideas? Thank you.
I've tried various methods of utilizing this and it seems as though its broken... I tried it as a DLL, actually packing it into a client version and displaying from GUI by still no luck. I was using this resource -
Answer by Bunny83 · Sep 23, 2013 at 01:25 PM
Well, in Unity's mono version GetProcessesByName simply calls GetProcesses and iterates over the whole list and compares the ProcessName. However there are processes which aren't accessible and throw an exception when you try to read the ProcessName. So you should iterate through the array returned by GetProcesses yourself and catch exceptions for those processes which aren't accessible.
Answer by Ashkan_gc · May 26, 2015 at 09:57 AM
This is fixed in later versions 4.6 at least. Just remember if the program is named explorer.exe you should pass "explorer" to the method and omit the exe extension.
Your answer
![](https://koobas.hobune.stream/wayback/20220613114651im_/https://answers.unity.com/themes/thub/images/avi.jpg)