How do I get the path of a binary in c#?
<p>For some reporting purposes I'm trying to get the location of a certain binary.</p>

<p>I was doing this, and it was working, but I'm now getting a NullReferenceException when I try to get testProc.MainModule.FileName; and I think it may be that the program is closing before I'm able to grab it. Is there any better way to do this?</p>

<pre><code>ProcessStartInfo testPSI = new ProcessStartInfo(RunOptions.TestBinary);
testPSI.RedirectStandardError = true;
testPSI.RedirectStandardOutput = true;
testPSI.UseShellExecute = false;
Process testProc = new Process();
testProc.StartInfo = testPSI;   
testProc.Start();
ret = testProc.MainModule.FileName;
testProc.Kill();
if (ret != null)
    return ret;
</code></pre>
