Added filename null or empty check. Start now calls the SetProcessHandle and SetProcessId function so that events are setup correctly. Bumped package version to 1.0.3

This commit is contained in:
MattMo 2024-09-12 20:37:25 -07:00
parent c78e599659
commit 5877042755
2 changed files with 9 additions and 5 deletions

View File

@ -15,7 +15,7 @@
<PackageTags>MontoyaTech;Process.Net</PackageTags> <PackageTags>MontoyaTech;Process.Net</PackageTags>
<AssemblyName>MontoyaTech.Process.Net</AssemblyName> <AssemblyName>MontoyaTech.Process.Net</AssemblyName>
<RootNamespace>MontoyaTech.Process.Net</RootNamespace> <RootNamespace>MontoyaTech.Process.Net</RootNamespace>
<Version>1.0.2</Version> <Version>1.0.3</Version>
<Company>MontoyaTech</Company> <Company>MontoyaTech</Company>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>

View File

@ -427,6 +427,9 @@ namespace MontoyaTech.Process.Net
if (startInfo == null) if (startInfo == null)
throw new InvalidOperationException("Process.StartInfo cannot be 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 processType = process.GetType();
var commandLine = new StringBuilder(); var commandLine = new StringBuilder();
@ -538,10 +541,11 @@ namespace MontoyaTech.Process.Net
childErrorHandle?.Dispose(); childErrorHandle?.Dispose();
} }
//Unsafely setup the process info. //Invoke SetProcessHandle
processType.GetField("_processId", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(process, (int)processInfo.dwProcessId); processType.GetMethod("SetProcessHandle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(process, new object[] { processHandle });
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 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 //Set the standard input writer if needed
if (startInfo.RedirectStandardInput) if (startInfo.RedirectStandardInput)