Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting the friendly name for a Process after starting it
    text
    copied!<p>I'm coding a watchdog service for an embedded system that monitors some proprietary processes and restarts them if necessary. (Nothing to do with <em>malware</em>, before you ask. It's just a business requirement)</p> <p>I need to <strong>retrieve the friendly name from a process I have just created</strong>, so that later I can retrieve that process using that name in order to monitor its health.</p> <p>My problem is as follows:</p> <ul> <li><p>If I try to read <code>Process.ProcessName</code> right after <code>Process.Start()</code>, I get an <code>InvalidOperationException</code> because it the process has not been fully created yet.</p></li> <li><p>The same happens if I use <code>Process.WaitForInputIdle()</code>, but since this requires a message pump and many executables could be UI-less launchers for the actual application, this might not be an option.</p></li> <li><p>I <strong>need</strong> to get the friendly name right after creating the process, before doing anything else.</p></li> </ul> <p>Here's a code snippet:</p> <pre><code>var startInfo = new ProcessStartInfo { FileName = "notepad.exe" }; var process = new Process(); process.StartInfo = startInfo; process.Start(); process.WaitForInputIdle(); var friendlyName = process.ProcessName; </code></pre> <p>This will throw an <code>InvalidOperationException</code> on the last line if the process being started is Firefox, for example.</p> <p>So how would I do this? Is there a safer method? </p> <p>EDIT: Added a code snippet for clarification. EDIT2: Rephrased the whole question for clarification, left irrelevant stuff out.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload