diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index 1805bda8f..0c177cc82 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -105,7 +105,7 @@ public static IEnumerable GetRemoteRepositories(ChocolateyConf { // As this is a static method, we need to call the global SimpleInjector container to get a registered service. var collectorService = SimpleInjectorContainer.Container.GetInstance(); - var processTree = collectorService.GetProcessesTree(); + var processTree = collectorService.GetProcessTree(); "chocolatey".Log().Debug("Process Tree: {0}", processTree); var userAgent = new StringBuilder() diff --git a/src/chocolatey/infrastructure.app/services/IProcessCollectorService.cs b/src/chocolatey/infrastructure.app/services/IProcessCollectorService.cs index 10695c505..d5640b4b3 100644 --- a/src/chocolatey/infrastructure.app/services/IProcessCollectorService.cs +++ b/src/chocolatey/infrastructure.app/services/IProcessCollectorService.cs @@ -40,6 +40,6 @@ public interface IProcessCollectorService /// /// The found process tree, returning null from this will throw an exception in Chocolatey CLI. /// - ProcessTree GetProcessesTree(); + ProcessTree GetProcessTree(); } } diff --git a/src/chocolatey/infrastructure.app/services/ProcessCollectorService.cs b/src/chocolatey/infrastructure.app/services/ProcessCollectorService.cs index 11631e3c7..164a4a1c3 100644 --- a/src/chocolatey/infrastructure.app/services/ProcessCollectorService.cs +++ b/src/chocolatey/infrastructure.app/services/ProcessCollectorService.cs @@ -17,7 +17,7 @@ public class ProcessCollectorService : IProcessCollectorService /// /// This method is not overridable on purpose, as once a tree is created it should not be changed. /// - public ProcessTree GetProcessesTree() + public ProcessTree GetProcessTree() { if (_processTree is null) { diff --git a/src/chocolatey/infrastructure/information/ProcessInformation.cs b/src/chocolatey/infrastructure/information/ProcessInformation.cs index eeb4fbc8f..75c896ca8 100644 --- a/src/chocolatey/infrastructure/information/ProcessInformation.cs +++ b/src/chocolatey/infrastructure/information/ProcessInformation.cs @@ -399,7 +399,13 @@ public static Process GetParentProcess(IntPtr handle) { var processUtilities = new ParentProcessHelperInternal(); - var status = NtQueryInformationProcess(handle, 0, ref processUtilities, Marshal.SizeOf(processUtilities), out _); + // https://learn.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntqueryinformationprocess#process_basic_information + // Retrieves a pointer to a PEB structure that can be used to determine whether the specified process is being debugged, + // and a unique value used by the system to identify the specified process. + // It also includes the `InheritedFromUniqueProcessId` value which we can use to look up the parent process directly. + const int processBasicInformation = 0; + + var status = NtQueryInformationProcess(handle, processBasicInformation, ref processUtilities, Marshal.SizeOf(processUtilities), out _); if (status != 0) {