Reputation: 2606
The following code throws an InvalidOperationException
: "Process was not started by this object, so requested information cannot be determined" when accessing the StartInfo
property.
using System;
using System.Diagnostics;
using System.Linq;
namespace ProcArgs
{
class Program
{
static void Main(string[] args)
{
var process = Process.GetProcessesByName("svchost").FirstOrDefault();
Console.WriteLine(process.StartInfo.Arguments);
}
}
}
So how does one get the command line of another already running process in .NET Core 2.2 (Windows)?
Upvotes: 6
Views: 1871