Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 77d599c

Browse files
authored
fix [System.Diagnostics.Process]::GetProcesses(computer) (#25784)
* fix [System.Diagnostics.Process]::GetProcesses(computer) * Add new test, update condition * Missed Using declaration * Catch exceptions
1 parent a761cd8 commit 77d599c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/System.Diagnostics.Process/src/System/Diagnostics/PerformanceCounterLib.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,14 @@ internal PerformanceMonitor(string machineName)
205205
private void Init()
206206
{
207207
#if FEATURE_REGISTRY
208-
_perfDataKey = Registry.PerformanceData;
208+
if (ProcessManager.IsRemoteMachine(_machineName))
209+
{
210+
_perfDataKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.PerformanceData, _machineName);
211+
}
212+
else
213+
{
214+
_perfDataKey = Registry.PerformanceData;
215+
}
209216
#endif
210217
}
211218

src/System.Diagnostics.Process/tests/ProcessTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Collections.Generic;
66
using System.ComponentModel;
7+
using System.DirectoryServices.ActiveDirectory;
78
using System.IO;
89
using System.Linq;
910
using System.Net;
@@ -920,6 +921,30 @@ public void GetProcesses_EmptyMachineName_ThrowsArgumentException()
920921
AssertExtensions.Throws<ArgumentException>(null, () => Process.GetProcesses(""));
921922
}
922923

924+
[Fact]
925+
public void GetProcesses_InvalidMachineName_ThrowsInvalidOperationException()
926+
{
927+
Assert.Throws<InvalidOperationException>(() => Process.GetProcesses(Guid.NewGuid().ToString()));
928+
}
929+
930+
[Fact]
931+
public void GetProcesses_RemoteMachinePath_ReturnsExpected()
932+
{
933+
try
934+
{
935+
Process[] processes = Process.GetProcesses(Environment.MachineName + "." + Domain.GetComputerDomain());
936+
Assert.NotEmpty(processes);
937+
}
938+
catch (ActiveDirectoryObjectNotFoundException)
939+
{
940+
//This will be thrown when the executing machine is not domain-joined, i.e. in CI
941+
}
942+
catch (PlatformNotSupportedException)
943+
{
944+
//System.DirectoryServices is not supported on all platforms
945+
}
946+
}
947+
923948
[Fact]
924949
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Retrieving information about local processes is not supported on uap")]
925950
public void GetProcessesByName_ProcessName_ReturnsExpected()

0 commit comments

Comments
 (0)