|
|
|
@@ -49,7 +49,7 @@ namespace MontoyaTech.Process.Net
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates that any windows created by the process cannot be pinned on the taskbar.
|
|
|
|
|
// This flag must be combined with STARTF_TITLEISAPPID.
|
|
|
|
|
/// This flag must be combined with STARTF_TITLEISAPPID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
STARTF_PREVENTPINNING = 0x00002000,
|
|
|
|
|
|
|
|
|
@@ -406,14 +406,30 @@ namespace MontoyaTech.Process.Net
|
|
|
|
|
/// <param name="creationFlags">If supplied this overrides all the creation flags for the process. Default is null.</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
public unsafe static System.Diagnostics.Process Create(System.Diagnostics.ProcessStartInfo startInfo, StartupFlags? startupFlags = null, CreationFlags? creationFlags = null)
|
|
|
|
|
public unsafe static System.Diagnostics.Process Start(System.Diagnostics.ProcessStartInfo startInfo, StartupFlags? startupFlags = null, CreationFlags? creationFlags = null)
|
|
|
|
|
{
|
|
|
|
|
if (startInfo == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(startInfo));
|
|
|
|
|
|
|
|
|
|
var process = new System.Diagnostics.Process();
|
|
|
|
|
|
|
|
|
|
process.StartInfo = startInfo;
|
|
|
|
|
|
|
|
|
|
Start(process, startupFlags, creationFlags);
|
|
|
|
|
|
|
|
|
|
return process;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public unsafe static void Start(System.Diagnostics.Process process, StartupFlags? startupFlags = null, CreationFlags? creationFlags = null)
|
|
|
|
|
{
|
|
|
|
|
var startInfo = process.StartInfo;
|
|
|
|
|
|
|
|
|
|
if (startInfo == null)
|
|
|
|
|
throw new InvalidOperationException("Process.StartInfo cannot be null.");
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(startInfo.FileName))
|
|
|
|
|
throw new InvalidOperationException("FileName cannot be null or empty.");
|
|
|
|
|
|
|
|
|
|
var processType = process.GetType();
|
|
|
|
|
|
|
|
|
|
var commandLine = new StringBuilder();
|
|
|
|
@@ -525,10 +541,11 @@ namespace MontoyaTech.Process.Net
|
|
|
|
|
childErrorHandle?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Unsafely setup the process info.
|
|
|
|
|
processType.GetField("_processId", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(process, (int)processInfo.dwProcessId);
|
|
|
|
|
processType.GetField("_haveProcessId", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(process, true);
|
|
|
|
|
processType.GetField("_processHandle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(process, processHandle);
|
|
|
|
|
//Invoke SetProcessHandle
|
|
|
|
|
processType.GetMethod("SetProcessHandle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(process, new object[] { processHandle });
|
|
|
|
|
|
|
|
|
|
//Invoke SetProcessId
|
|
|
|
|
processType.GetMethod("SetProcessId", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(process, new object[] { (int)processInfo.dwProcessId });
|
|
|
|
|
|
|
|
|
|
//Set the standard input writer if needed
|
|
|
|
|
if (startInfo.RedirectStandardInput)
|
|
|
|
@@ -551,11 +568,9 @@ namespace MontoyaTech.Process.Net
|
|
|
|
|
if (startInfo.RedirectStandardError)
|
|
|
|
|
{
|
|
|
|
|
var reader = new StreamReader(new FileStream(parentErrorHandle, FileAccess.Read, 4096, false), startInfo.StandardErrorEncoding ?? GetEncoding(GetConsoleOutputCP()), true, 4096);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
processType.GetField("_standardError", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(process, reader);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return process;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|