Hello!
I am writing an application in Unity that requires another application to be running. I have been able to successfully start another program from Unity, but I have not been able to close it. I am
using System.Diagnostics
...
Process p = new Process();
p.StartInfo.FileName = @"C:\path o\program.exe";
p.Start(); // works up to this point
p.CloseMainWindow(); // throws a compiler error
When I try to run this code, I get a compile error:
Type 'System.Diagnostics.Process' does not contain a definition for 'CloseMainWindow' and no extension method 'CloseMainWindow' of type 'System.Diagnostics.Process' could be found (are you missing a using directive or an assembly reference?)
I get a similar error for the Kill() method.
Both the Kill() and CloseMainWindow() methods are suggested by intellisense in the Monodevelop IDE, and documented in the C# .NET
My theory is that Unity has blocked some features of the .NET framework to prevent a Unity process from shutting down other processes. I have tried using System.Reflection to look inside the Process class, but it isn’t working for some mysterious reason (this being my first time using reflection in C#).
How can I close this extra process when the user closes Unity?
Thanks!