Why is StartInfo (ProcessStartInfo) always empty?



Answers

You are getting a different Process instance back from GetProcessesByName that falls into the latter case of the statement on MSDN.

Question

According to MSDN:

If you did not use the Start method to start a process, the StartInfo property does not reflect the parameters used to start the process. For example, if you use GetProcesses to get an array of processes running on the computer, the StartInfo property of each Process does not contain the original file name or arguments used to start the process.

Okay, that makes perfect sense. My question is why are these parameters blank even when you do use Process.Start()?

For example:

    Dim startInfo As New ProcessStartInfo("firefox.exe")
    startInfo.Arguments = "www..com"
    startInfo.WindowStyle = ProcessWindowStyle.Minimized
    Process.Start(startInfo)
    For Each proc As Process In Process.GetProcessesByName("firefox")
        Debug.Print(String.Format("ProcessID={0}; Arguments={1}", _
        proc.Id, proc.StartInfo.Arguments))
    Next proc

In this case even though I provided Arguments, that property is still empty:

alt text http://www.sg-squared.com/images/startinfo.png

What gives?




System.Diagnostics.Process.GetCurrentProcess().StartInfo.Arguments



How to access command line parameters outside of Main in C#

Call Environment.GetCommandLineArgs().




You probably want a

static void Main(string[] args)
{
}

where args contains the arguments you passed in






Links



Tags