I am developing an application in which a number of instances of a process, A, depend on a single instance of a process, B. The idea is that one of the instances of process A st
You can try to use the ManagementClass to launch a process and pass some CreateFlags, more specifically, the DETACHED_PROCESS
flag. (You'll need to reference System.Management
.)
private static void Main()
{
using (var managementClass = new ManagementClass("Win32_Process"))
{
var processInfo = new ManagementClass("Win32_ProcessStartup");
processInfo.Properties["CreateFlags"].Value = 0x00000008;
var inParameters = managementClass.GetMethodParameters("Create");
inParameters["CommandLine"] = "notepad.exe";
inParameters["ProcessStartupInformation"] = processInfo;
var result = managementClass.InvokeMethod("Create", inParameters, null);
if ((result != null) && ((uint)result.Properties["ReturnValue"].Value != 0))
{
Console.WriteLine("Process ID: {0}", result.Properties["ProcessId"].Value);
}
}
Console.ReadKey();
}
At least on my machine notepad is not considered a child process of my console test application.