processStartInfo run exe?

369 Views Asked by At

when you invoke :

ProcessStartInfo startInfo = new ProcessStartInfo("someExecutable.exe");

Does this actually run the someExecutable.exe or does it just monitor that? I am essentially seeing if this can be used to read output from an already running exe or if it will call the exe.

I am trying to find a way to just monitor and record a few values from an already running exe.

1

There are 1 best solutions below

2
On

Does this actually run the someExecutable.exe or dies it just monitor that?

The answer is neither ... nor! The MSDN article about the ProcessStartInfo states:

You can use the ProcessStartInfo class for better control over the process you start. You must at least set the FileName property, either manually or using the constructor.

and also

ProcessStartInfo is used together with the Process component. When you start a process using the Process class, you have access to process information in addition to that available when attaching to a running process.

Using the ProcessStartInfo class you can neither start, nor monitor a process.

However depending on what you need to monitor (for example the output of the executable) you can use the ProcessStartInfo class to redirect the ouput of the process you are going to start programmatically. In order to do that you need to set the RedirectStandardOutput property of the ProcessStartInfo class. So you need the class in order to allow/configure process monitoring assuming you will start the process programmatically.

The commented MSDN example to clarify my answer:

// Process is NOT started yet! process name is set
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
// Process is NOT started yet! process object is initialized with the process info like filename and so on. 
Process.Start(startInfo);
// Process is NOT started yet! process arguments are set. 
// The equivalent command line in a shell would be: c:\>IExplore.exe www.northwindtraders.com ENTER is NOT pressed yet!
startInfo.Arguments = "www.northwindtraders.com";
// NOW the process is executed/started => 
// c:\>IExplore.exe www.northwindtraders.com <= ENTER is pressed, process is started/running!
// c:\>
Process.Start(startInfo);